Skip to content

@hakank /gist:944824
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Gambler's Ruin simulation in K (Kona)
/ 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.