19 lines
529 B
Text
19 lines
529 B
Text
include xpllib; \for Print
|
|
|
|
func real SleepingBeauty(Reps);
|
|
int Reps, Wakings, Heads, Coin, I;
|
|
[Wakings:= 0; Heads:= 0;
|
|
for I:= 0 to Reps-1 do
|
|
[Coin:= Ran(2); \heads = 0, tails = 1 say
|
|
Wakings:= Wakings + 1;
|
|
if Coin = 0 then Heads:= Heads + 1
|
|
else Wakings:= Wakings + 1;
|
|
];
|
|
Print("Wakings over %d repetitions = %d\n", Reps, Wakings);
|
|
return float(Heads) / float(Wakings) * 100.;
|
|
];
|
|
|
|
real PC;
|
|
[PC:= SleepingBeauty(1_000_000);
|
|
Print("Percentage probability of heads on waking = %1.6f\%\n", PC);
|
|
]
|