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 ]