Advertisement
Guest User

rolling a die (@erugli)

a guest
Nov 30th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 0.46 KB | None | 0 0
  1. _D = Dict{Tuple{Int,Int},Int}()
  2.  
  3. # count number of ways to write 't' as sum of 'l' integers in [1,6]
  4. count = function(t,l)
  5.     get!(_D,(t,l)) do
  6.       if l < 1
  7.           0
  8.       elseif l == 1
  9.           1 <= t <= 6 ? 1 : 0
  10.       else
  11.           sum(Array{Int}(map(i -> count(t-i,l-1), 1:6)))
  12.       end
  13.     end
  14. end
  15.  
  16. expected_stopping_time = sum(map(l->l*(1//6)^l*sum(map(i->i*count(6+i,l-1),1:6)),3:13))
  17. # = 9136402849//2176782336 ≈ 4.19720552574348
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement