Sleeping Beauty problem: Difference between revisions

Content added Content deleted
(Add Red)
(Added 11l)
Line 31: Line 31:





=={{header|11l}}==
{{trans|Python}}

<lang 11l>F sleeping_beauty_experiment(repetitions)
Run the Sleeping Beauty Problem experiment `repetitions` times, checking to see
how often we had heads on waking Sleeping Beauty.
V gotheadsonwaking = 0
V wakenings = 0
L 0 .< repetitions
V coin_result = random:choice([‘heads’, ‘tails’])

// On Monday, we check if we got heads.
wakenings++
I coin_result == ‘heads’
gotheadsonwaking++

// If tails, we do this again, but of course we will not add as if it was heads..
I coin_result == ‘tails’
wakenings++
I coin_result == ‘heads’
gotheadsonwaking++ // never done

print(‘Wakenings over ’repetitions‘ experiments: ’wakenings)

R Float(gotheadsonwaking) / wakenings

V CREDENCE = sleeping_beauty_experiment(1'000'000)
print(‘Results of experiment: Sleeping Beauty should estimate a credence of: ’CREDENCE)</lang>

{{out}}
<pre>
Wakenings over 1000000 experiments: 1500892
Results of experiment: Sleeping Beauty should estimate a credence of: 0.332540916
</pre>


=={{header|Arturo}}==
=={{header|Arturo}}==