2023-07-01 11:58:00 -04:00
|
|
|
_iterations = 1000000
|
|
|
|
|
|
|
|
|
|
local fn SleepingBeauty
|
2024-07-13 15:19:22 -07:00
|
|
|
NSUInteger i
|
|
|
|
|
CGFloat heads = 0, sleep = 0
|
2023-07-01 11:58:00 -04:00
|
|
|
|
2024-07-13 15:19:22 -07:00
|
|
|
for i = 1 to _iterations
|
|
|
|
|
NSInteger coinToss = int( rnd(2) )
|
|
|
|
|
sleep++
|
|
|
|
|
if coinToss = 1 then heads++ else sleep++
|
|
|
|
|
next
|
2023-07-01 11:58:00 -04:00
|
|
|
|
2024-07-13 15:19:22 -07:00
|
|
|
printf @"Awakenings over %lld sleep cycles = %.f", _iterations, sleep
|
|
|
|
|
printf @"Percent probability of heads on waking = %.4f%%", heads / sleep * 100
|
2023-07-01 11:58:00 -04:00
|
|
|
end fn
|
|
|
|
|
|
|
|
|
|
randomize
|
|
|
|
|
|
|
|
|
|
fn SleepingBeauty
|
|
|
|
|
|
|
|
|
|
HandleEvents
|