RosettaCodeData/Task/Monty-Hall-problem/Forth/monty-hall-problem-1.fth
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

17 lines
372 B
Forth

include random.fs
variable stay-wins
variable switch-wins
: trial ( -- )
3 random 3 random ( prize choice )
= if 1 stay-wins +!
else 1 switch-wins +!
then ;
: trials ( n -- )
0 stay-wins ! 0 switch-wins !
dup 0 do trial loop
cr stay-wins @ . [char] / emit dup . ." staying wins"
cr switch-wins @ . [char] / emit . ." switching wins" ;
1000 trials