How to resolve the algorithm Sleeping Beauty problem step by step in the F# programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sleeping Beauty problem step by step in the F# programming language

Table of Contents

Problem Statement

In decision theory, The Sleeping Beauty Problem is a problem invented by Arnold Zoboff and first publicized on Usenet. The experimental subject, named Sleeping Beauty, agrees to an experiment as follows:
Sleeping Beauty volunteers to be put into a deep sleep on a Sunday. There is then a fair coin toss. If this coin toss comes up heads, Sleeping Beauty wakes once (on Monday) and is asked to estimate the probability that the coin toss was heads. Her estimate is recorded and she is then put back to sleep for 2 days until Wednesday, at which time the experiment's results are tallied.

If instead the coin toss is tails, Sleeping Beauty wakes as before on Monday and asked to estimate the probability the coin toss was heads, but is then given a drug which makes her forget that she had been woken on Monday before being put back to sleep again. She then wakes only 1 day later, on Tuesday. She is then asked (on Tuesday) again to guess the probability that the coin toss was heads or tails. She is then put back to sleep and awakes as before 1 day later, on Wednesday.

Some decision makers have argued that since the coin toss was fair Sleeping Beauty should always estimate the probability of heads as 1/2, since she does not have any additional information. Others have disagreed, saying that if Sleeping Beauty knows the study design she also knows that she is twice as likely to wake up and be asked to estimate the coin flip on tails than on heads, so the estimate should be 1/3 heads. Given the above problem, create a Monte Carlo estimate of the actual results. The program should find the proportion of heads on waking and asking Sleeping Beauty for an estimate, as a credence or as a percentage of the times Sleeping Beauty is asked the question.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sleeping Beauty problem step by step in the F# programming language

Source code in the fsharp programming language

// Sleeping Beauty: Nigel Galloway. May 16th., 2021
let heads,woken=let n=System.Random() in {1..1000}|>Seq.fold(fun(h,w) g->match n.Next(2) with 0->(h+1,w+1) |_->(h,w+2))(0,0)
printfn "During 1000 tosses Sleeping Beauty woke %d times, %d times the toss was heads. %.0f%% of times heads had been tossed when she awoke" woken heads (100.0*float(heads)/float(woken))


  

You may also check:How to resolve the algorithm Copy stdin to stdout step by step in the sed programming language
You may also check:How to resolve the algorithm Bioinformatics/base count step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Count in factors step by step in the Ada programming language
You may also check:How to resolve the algorithm String concatenation step by step in the Ada programming language
You may also check:How to resolve the algorithm Day of the week step by step in the PHP programming language