Sleeping Beauty problem: Difference between revisions

added Pascal
m (→‎Excel LAMBDA: Inlined a generic lambda to reduce dependency.)
(added Pascal)
Line 180:
Results of experiment: Sleeping Beauty should estimate a credence of: 0.33374768428058316
</pre>
=={{header|Pascal}}==
 
{{trans|Phix}}
<lang pascal>
program sleepBeau;
uses
sysutils; //Format
const
iterations = 1000*1000;
fmt = 'Wakings over %d repetitions = %d'+#13#10+
'Percentage probability of heads on waking = %8.5f%%';
var
i,
heads,
wakings,
flip: Uint32;
begin
randomize;
for i :=1 to iterations do
Begin
flip := random(2)+1;//-- 1==heads, 2==tails
inc(wakings,1 + Ord(flip=2));
inc(heads,Ord(flip=1));
end;
writeln(Format(fmt,[iterations,wakings,heads/wakings*100]));
end.</lang>
{{out}}
<pre>Wakings over 1000000 repetitions = 1499741
Percentage probability of heads on waking = 33.35636%</pre>
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
Anonymous user