Jump to content

Sleeping Beauty problem: Difference between revisions

add gwbasic
(add gwbasic)
Line 138:
Wakings over 1,000,000 repetitions = 1,499,718
Percentage probability of heads on waking = 33.358405%
</pre>
 
==={{header|GW-BASIC}}===
In this simulation, Sleeping Beauty flips a coin of her own.
<lang gwbasic>10 RANDOMIZE TIMER
20 MONDAY = 0 : TUESDAY = 1
30 HEADS = 0 : TAILS = 1
40 FOR SB = 1 TO 300000!
50 IF COIN = HEADS THEN GOSUB 150 ELSE GOSUB 210
60 COIN = INT(RND*2)
70 NEXT SB
80 PRINT "Sleeping Beauty was put through this experiment ";SB-1;" times."
90 PRINT "She was awoken ";AWAKE;" times."
100 PRINT "She guessed heads ";CHEADS+WHEADS;" times."
110 PRINT "Those guesses were correct ";CHEADS;" times. ";100*CHEADS/(CHEADS+WHEADS);"%"
120 PRINT "She guessed tails ";WTAILS+CTAILS;" times."
130 PRINT "Those guesses were correct ";CTAILS;" times. ";100*CTAILS/(CTAILS+WTAILS);"%"
140 END
150 REM interview if the coin came up heads
160 AWAKE = AWAKE + 1
170 NHEADS = NHEADS + 1
180 GUESS = INT(RND*2)
190 IF GUESS = HEADS THEN CHEADS = CHEADS + 1 ELSE WTAILS = WTAILS + 1
200 RETURN
210 REM interviews if the coin came up tails
220 FOR DAY = MONDAY TO TUESDAY
230 AWAKE = AWAKE + 1
240 GUESS = INT(RND*2)
250 IF GUESS = HEADS THEN WHEADS = WHEADS + 1 ELSE CTAILS = CTAILS + 1
260 NEXT DAY
270 RETURN</lang>
{{out}}<pre>
Sleeping Beauty was put through this experiment 300000 times.
She was awoken 449981 times.
She guessed heads 224569 times.
Those guesses were correct 74985 times. 33.39063 %
She guessed tails 225412 times.
Those guesses were correct 150378 times. 66.71251 %
</pre>
 
781

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.