Sleeping Beauty problem: Difference between revisions

Content added Content deleted
mNo edit summary
(Added XPL0 example.)
Line 1,008: Line 1,008:
Wakings over 1,000,000 repetitions = 1,500,321
Wakings over 1,000,000 repetitions = 1,500,321
Percentage probability of heads on waking = 33.304806%
Percentage probability of heads on waking = 33.304806%
</pre>

=={{header|XPL0}}==
{{trans|Wren}}
<syntaxhighlight lang "XPL0">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);
]</syntaxhighlight>
{{out}}
<pre>
Wakings over 1000000 repetitions = 1500013
Percentage probability of heads on waking = 33.332178%
</pre>
</pre>