RosettaCodeData/Task/Probabilistic-choice/Quackery/probabilistic-choice.quackery
2023-07-01 13:44:08 -04:00

72 lines
1.8 KiB
Text

[ $ "bigrat.qky" loadfile ] now!
( --------------- zen object orientation -------------- )
[ immovable
]this[ swap do ]done[ ] is object ( [ --> )
[ ]'[ ] is method ( --> [ )
[ method
[ dup share
swap put ] ] is localise ( --> )
[ method [ release ] ] is delocalise ( --> )
( ------------------ rand-gen methods ----------------- )
[ method
[ dup take
2 split drop
' [ 0 0 ] join
swap put ] ] is reset-gen ( --> [ )
[ method
[ dup take
dup 2 peek 1+
swap 2 poke
dup 1 peek random
over 0 peek <
if
[ dup 3 peek 1+
swap 3 poke ]
swap put ] ] is rand-gen ( --> [ )
[ method
[ dup echo say ": "
share
dup 2 peek dup echo
say " trials" cr
say " Actual: "
over 3 peek
swap 10 point$ echo$ cr
say " Expected: "
dup 0 peek
swap 1 peek
10 point$ echo$ cr
cr ] ] is report ( --> [ )
( ------------------ rand-gen objects ----------------- )
[ object [ 1 5 0 0 ] ] is aleph ( [ --> )
[ object [ 1 6 0 0 ] ] is beth ( [ --> )
[ object [ 1 7 0 0 ] ] is gimel ( [ --> )
[ object [ 1 8 0 0 ] ] is daleth ( [ --> )
[ object [ 1 9 0 0 ] ] is he ( [ --> )
[ object [ 1 10 0 0 ] ] is waw ( [ --> )
[ object [ 1 11 0 0 ] ] is zayin ( [ --> )
[ object [ 1759 27720 0 0 ] ] is heth ( [ --> )
' [ aleph beth gimel daleth he waw zayin heth ]
dup witheach [ reset-gen swap do ]
dup witheach
[ 1000000 times
[ rand-gen over do ]
drop ]
witheach [ report swap do ]