Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
31
Task/Monty-Hall-problem/REXX/monty-hall-problem-1.rexx
Normal file
31
Task/Monty-Hall-problem/REXX/monty-hall-problem-1.rexx
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* REXX ***************************************************************
|
||||
* 30.08.2013 Walter Pachl derived from Java
|
||||
**********************************************************************/
|
||||
Call time 'R'
|
||||
switchWins = 0;
|
||||
stayWins = 0
|
||||
Do plays = 1 To 1000000
|
||||
doors.=0
|
||||
r=r3()
|
||||
doors.r=1
|
||||
choice = r3()
|
||||
Do Until shown<>choice & doors.shown=0
|
||||
shown = r3()
|
||||
End
|
||||
If doors.choice=1 Then
|
||||
stayWins=stayWins+1
|
||||
Else
|
||||
switchWins=switchWins+1
|
||||
End
|
||||
Say "Switching wins " switchWins " times."
|
||||
Say "Staying wins " stayWins " times."
|
||||
Say 'REXX:' time('E') 'seconds'
|
||||
Call time 'R'
|
||||
'ziegen'
|
||||
Say 'PL/I:' time('E') 'seconds'
|
||||
Say ' '
|
||||
Call time 'R'
|
||||
'java ziegen'
|
||||
Say 'NetRexx:' time('E') 'seconds'
|
||||
Exit
|
||||
r3: Return random(2)+1
|
||||
14
Task/Monty-Hall-problem/REXX/monty-hall-problem-2.rexx
Normal file
14
Task/Monty-Hall-problem/REXX/monty-hall-problem-2.rexx
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/*REXX program simulates any number of trials of the classic TV show Monty Hall problem.*/
|
||||
parse arg # seed . /*obtain the optional args from the CL.*/
|
||||
if #=='' | #=="," then #= 1000000 /*Not specified? Then 1 million trials*/
|
||||
if datatype(seed, 'W') then call random ,, seed /*Specified? Use as a seed for RANDOM.*/
|
||||
wins.= 0 /*wins.0 ≡ stay, wins.1 ≡ switching.*/
|
||||
do #; door. = 0 /*initialize all doors to a value of 0.*/
|
||||
car= random(1, 3); door.car= 1 /*the TV show hides a car randomly. */
|
||||
?= random(1, 3); _= door.? /*the contestant picks a (random) door.*/
|
||||
wins._ = wins._ + 1 /*bump count of type of win strategy.*/
|
||||
end /*#*/ /* [↑] perform the loop # times. */
|
||||
/* [↑] door values: 0≡goat 1≡car */
|
||||
say 'switching wins ' format(wins.0 / # * 100, , 1)"% of the time."
|
||||
say ' staying wins ' format(wins.1 / # * 100, , 1)"% of the time." ; say
|
||||
say 'performed ' # " times with 3 doors." /*stick a fork in it, we're all done. */
|
||||
Loading…
Add table
Add a link
Reference in a new issue