Created
April 27, 2011 18:14
-
-
Save hakank/944824 to your computer and use it in GitHub Desktop.
Gambler's Ruin simulation in K (Kona)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ 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