Skip to content

Instantly share code, notes, and snippets.

@fwip
Created December 12, 2012 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fwip/4269732 to your computer and use it in GitHub Desktop.
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.
#!/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