Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
51
Task/Sleeping-Beauty-problem/CLU/sleeping-beauty-problem.clu
Normal file
51
Task/Sleeping-Beauty-problem/CLU/sleeping-beauty-problem.clu
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
% This program needs to be merged with PCLU's "misc" library
|
||||
% to use the random number generator.
|
||||
|
||||
experiment = cluster is run
|
||||
rep = null
|
||||
|
||||
own awake: int := 0
|
||||
own awake_heads: int := 0
|
||||
|
||||
% Returns true if heads, false if tails
|
||||
coin_toss = proc () returns (bool)
|
||||
return(random$next(2)=1)
|
||||
end coin_toss
|
||||
|
||||
% Do the experiment once
|
||||
do_experiment = proc ()
|
||||
heads: bool := coin_toss()
|
||||
|
||||
% monday - wake up
|
||||
awake := awake + 1
|
||||
if heads then
|
||||
awake_heads := awake_heads + 1
|
||||
return
|
||||
end
|
||||
|
||||
% tuesday - wake up if tails
|
||||
awake := awake + 1
|
||||
end do_experiment
|
||||
|
||||
% Run the experiment N times
|
||||
run = proc (n: int) returns (real)
|
||||
awake := 0
|
||||
awake_heads := 0
|
||||
|
||||
for i: int in int$from_to(1,n) do
|
||||
do_experiment()
|
||||
end
|
||||
|
||||
return(real$i2r(awake_heads) / real$i2r(awake))
|
||||
end run
|
||||
end experiment
|
||||
|
||||
start_up = proc ()
|
||||
N = 1000000
|
||||
|
||||
po: stream := stream$primary_output()
|
||||
stream$puts(po, "Chance of waking up with heads: ")
|
||||
|
||||
chance: real := experiment$run(N)
|
||||
stream$putl(po, f_form(chance, 1, 6))
|
||||
end start_up
|
||||
Loading…
Add table
Add a link
Reference in a new issue