18 lines
581 B
Text
18 lines
581 B
Text
// sleeping beauty problem - translated from the Wren sample, via Pluto
|
|
|
|
sleepingBeauty = function( reps )
|
|
wakings = 0
|
|
heads = 0
|
|
for _ in range( 1, reps )
|
|
wakings += 1
|
|
if rnd < 0.5 then // rnd returns a randome number in [0..1)
|
|
heads += 1 // [0..0.5) = heads
|
|
else
|
|
wakings += 1 // [0.5..1.0) = tails
|
|
end if
|
|
end for
|
|
print "Wakings over " + reps + " repetitions = " + wakings
|
|
return ( heads / wakings ) * 100
|
|
end function
|
|
|
|
print "Percentage probability of heads on waking = " + sleepingBeauty( 1000000 )
|