Skip to content

Instantly share code, notes, and snippets.

@diasjorge
Created October 31, 2014 09:46
Show Gist options
  • Save diasjorge/16b529bd80f56123d9ad to your computer and use it in GitHub Desktop.
Save diasjorge/16b529bd80f56123d9ad to your computer and use it in GitHub Desktop.
require 'pp'
class Array
def average
inject(0.0) { |sum, e| sum + e } / length
end
end
res = {}
['naoise','alejandro','erick'].each do |name|
res[name] = 1_000_000.times.map { rand }.average
end
winner = res.sort_by { |k,v| v }.last.first
puts "And the winner is #{winner}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment