Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View 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