public
Last active

Gambler's Ruin simulation in K (Kona)

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
/ generate 10 random -1, 1 and
/ and count cumulative
+\ 10 ? (-1;1)
 
/ sample result
/ -1 0 1 0 1 2 1 2 1 2
 
/ just the last result:
+/x: 100 ? (-1;1)
 
/ sample result:
/ 2
 
/ define two help functions
mean: {+/x % #x}
table:{t[<t:(s:?x),'#:'=x]}
 
/ run the simulation of 100 games 100 times
/ and show the frequency distribution of the
/ results
table @ {+/100 ? (-1;1)} ' !100
 
/ sample result
/ (-26 1
/ -22 2
/ -16 2
/ -14 5
/ -12 4
/ -10 3
/ -8 5
/ -6 8
/ -4 11
/ -2 10
/ 0 6
/ 2 9
/ 4 7
/ 6 6
/ 8 6
/ 10 4
/ 12 3
/ 14 3
/ 16 3
/ 18 1
/ 20 1)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.