Skip to content

Instantly share code, notes, and snippets.

@avescodes
Created August 27, 2010 15:22
Show Gist options
  • Save avescodes/553562 to your computer and use it in GitHub Desktop.
Save avescodes/553562 to your computer and use it in GitHub Desktop.
candidates = [:burke, :kevin, :lisa, :mark, :afolabi, :brent, :tiffany, :cary, :peer, :brock, :john, :keith, :brad, :ryan]
# Let's let everyone make their own choice :P
occurrences = candidates.inject({}) {|h,candidate| h[candidate] = candidates.sample(3); h}
# Now tally them up
counts = occurrences.values.flatten.inject({}) {|h,person| h[person] ||= 0; h[person] += 1; h}
sorted = counts.sort {|a,b| b.last <=> a.last }
puts sorted.first(3).map(&:first).join(', ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment