Sleeping Beauty problem: Difference between revisions
Content added Content deleted
m (→{{header|Go}}: Added libheader) |
|||
Line 344: | Line 344: | ||
Results of experiment: Sleeping Beauty should estimate a credence of: 0.33374768428058316 |
Results of experiment: Sleeping Beauty should estimate a credence of: 0.33374768428058316 |
||
</pre> |
</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}}== |
=={{header|Nim}}== |