Created
December 12, 2012 17:20
-
-
Save fwip/4269732 to your computer and use it in GitHub Desktop.
Example script that calculates the probability of getting each score in a "roll 4 six sided dice, drop the lowest, then sum" scheme.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/ruby | |
# Calculates the distribution of 4d6, drop lowest | |
scores = {} | |
(1..6).each do |i| | |
(1..6).each do |j| | |
(1..6).each do |k| | |
(1..6).each do |l| | |
dice = [i, j, k, l].sort | |
dice.shift | |
score = dice.inject :+ | |
scores[score] ||= 0 | |
scores[score] += 1 | |
end | |
end | |
end | |
end | |
scores.each do |k, v| | |
puts "#{k}\t#{v}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment