Skip to content

Instantly share code, notes, and snippets.

@Frost
Created July 29, 2012 11:58
Show Gist options
  • Save Frost/3198175 to your computer and use it in GitHub Desktop.
Save Frost/3198175 to your computer and use it in GitHub Desktop.
Made a program that rolls 100 pairs of dice and counts each result. Now in ruby.
number_of_rolls = 100
stats = Hash.new {0}
rolls = []
outcome_translation = {
2 => "two",
3 => "three",
4 => "four",
5 => "five",
6 => "six",
7 => "seven",
8 => "eight",
9 => "nine",
10 => "ten",
11 => "eleven",
12 => "twelve"
}
number_of_rolls.times do
roll = rand(1..6) + rand(1..6)
rolls << roll
stats[roll] += 1
end
outcome_translation.map do |number, translation|
puts "%s:\t%2d" % [translation, stats[number]]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment