RosettaCodeData/Task/Sleeping-Beauty-problem/Pluto/sleeping-beauty-problem.pluto
2026-04-30 12:34:36 -04:00

18 lines
620 B
Text

do -- sleeping beauty problem - translated from the Wren sample, via Agena
local function sleepingBeauty( reps : number ) : number
local wakings, heads = 0, 0
for _ = 1, reps do
wakings += 1
if math.random() < 0.5 then
heads += 1 -- [0..0.5) = heads
else
wakings += 1 -- [0.5..1.0) = tails
end
end
print( $"Wakings over {reps} repetitions = {wakings}" )
return ( heads / wakings ) * 100
end
print( $"Percentage probability of heads on waking = { sleepingBeauty( 1_000_000 ) }" )
end