Created
August 4, 2014 22:38
-
-
Save ror3d/2c93b6e38bbbfaf3026c to your computer and use it in GitHub Desktop.
Revisions
-
Rcrmn created this gist
Aug 4, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ min_to_succ = 6 puts 'How many d10 should be rolled?' n = gets.chomp.to_i comb = (1..10).to_a.map { |x| [x] } for i in 2..n comb2 = [] for j in 1..10 for k in 0...comb.length comb2 << (comb[k] + [j]) end end comb = comb2 end succ = [0]*(2*n+1) comb.each do |x| s = 0 x.each do |y| s += (y >= min_to_succ ? 1 : (y == 1 ? -1 : 0)) end succ[n+s] += 1 end sum = succ.reduce(:+).to_f succ.each_with_index do |x, i| s = i - n puts "Results with %d %s: \t%0.3g%%" % [ s.abs, (s < 0 ? 'fails' : 'succ.'), x/sum*100] end puts "Failed results: \t%0.3g%%" % [ succ[0...n].reduce(:+) / sum * 100 ] puts "Unsuccessful results \t%0.3g%%" % [ succ[n] / sum * 100 ] puts "Successful results: \t%0.3g%%" % [ succ.drop(n+1).reduce(:+) / sum * 100 ]