Guest User

Untitled

a guest
Jul 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. def combs(n)
  2. if n == 1 then
  3. (1..6).each {|x| yield [x] }
  4. else
  5. (1..6).each {|x| combs(n -1) {|arr| yield arr.unshift x ; arr.shift x } }
  6. end
  7. end
  8.  
  9. def prob(n, diff)
  10. total, hits = 6**n, 0
  11. combs(n) {|arr| hits+= 1 if arr.inject(0, &:+) > diff }
  12. hits.to_f/ total
  13. end
Add Comment
Please, Sign In to add comment