Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def combs(n)
- if n == 1 then
- (1..6).each {|x| yield [x] }
- else
- (1..6).each {|x| combs(n -1) {|arr| yield arr.unshift x ; arr.shift x } }
- end
- end
- def prob(n, diff)
- total, hits = 6**n, 0
- combs(n) {|arr| hits+= 1 if arr.inject(0, &:+) > diff }
- hits.to_f/ total
- end
Add Comment
Please, Sign In to add comment