Sleeping Beauty problem: Difference between revisions

m (→‎{{header|Go}}: Added libheader)
Line 344:
Results of experiment: Sleeping Beauty should estimate a credence of: 0.33374768428058316
</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>ClearAll[SleepingBeautyExperiment]
SleepingBeautyExperiment[reps_Integer] := Module[{gotheadsonwaking, wakenings, coinresult},
gotheadsonwaking = 0;
wakenings = 0;
Do[
coinresult = RandomChoice[{"heads", "tails"}];
wakenings++;
If[coinresult === "heads",
gotheadsonwaking++;
,
wakenings++;
]
,
{reps}
];
Print["Wakenings over ", reps, " experiments: ", wakenings];
gotheadsonwaking/wakenings
]
out = N@SleepingBeautyExperiment[10^6];
Print["Results of experiment: Sleeping Beauty should estimate a credence of: ", out]</lang>
{{out}}
<pre>Wakenings over 1000000 experiments: 1499714
Results of experiment: Sleeping Beauty should estimate a credence of: 0.333588</pre>
 
=={{header|Nim}}==
1,111

edits