Skip to content

Instantly share code, notes, and snippets.

@davidtrogers
Created February 17, 2013 03:38
Show Gist options
  • Save davidtrogers/4970002 to your computer and use it in GitHub Desktop.
Save davidtrogers/4970002 to your computer and use it in GitHub Desktop.
seen, values = {}, []
100.times { |i| values << rand(100) }
values.each { |value| seen[value] = (seen[value] || 0) + 1 }
seen
=> { 32=>1, 11=>2, 64=>2, 62=>4, 44=>4, 86=>2, 34=>5, 96=>2,
89=>2, 70=>1, 47=>1, 99=>3, 39=>1, 67=>1, 35=>1, 71=>2,
40=>2, 49=>1, 85=>1, 45=>1, 81=>2, 74=>2, 23=>2, 42=>3,
63=>1, 14=>1, 50=>2, 25=>2, 53=>1, 19=>2, 24=>2, 29=>2,
68=>2, 31=>3, 33=>2, 4=>1, 55=>1, 37=>3, 36=>1, 76=>1,
18=>1, 8=>2, 26=>1, 10=>2, 79=>1, 84=>2, 93=>1, 41=>1,
3=>1, 38=>1, 1=>1, 82=>1, 88=>1, 69=>1, 98=>2, 66=>1,
95=>1, 72=>1, 78=>1, 12=>1, 59=>1 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment