Sleeping Beauty problem: Difference between revisions
→{{header|Raku}}: Add a Raku example
Thundergnat (talk | contribs) (→{{header|Raku}}: Add a Raku example) |
|||
Line 184:
Results of experiment: Sleeping Beauty should estimate a credence of: 0.333542254953276
</pre>
=={{header|Raku}}==
<lang perl6>sub sleeping-beauty ($trials) {
my $gotheadsonwaking = 0;
my $wakenings = 0;
^$trials .map: {
given <Heads Tails>.roll {
++$wakenings;
when 'Heads' { ++$gotheadsonwaking }
when 'Tails' { ++$wakenings }
}
}
say "Wakenings over $trials experiments: ", $wakenings;
$gotheadsonwaking / $wakenings
}
say "Results of experiment: Sleeping Beauty should estimate a credence of: ", sleeping-beauty(1_000_000);</lang>
{{out}}
<pre>Wakenings over 1000000 experiments: 1500040
Results of experiment: Sleeping Beauty should estimate a credence of: 0.333298</pre>
=={{header|Wren}}==
|