Sleeping Beauty problem: Difference between revisions
Content added Content deleted
m (→{{header|FutureBasic}}: add indents) |
(Added Algol 68) |
||
Line 68: | Line 68: | ||
Results of experiment: Sleeping Beauty should estimate a credence of: 0.332540916 |
Results of experiment: Sleeping Beauty should estimate a credence of: 0.332540916 |
||
</pre> |
</pre> |
||
=={{header|ALGOL 68}}== |
|||
{{Trans|Wren}} |
|||
In Algol 68, the generated random numbers are in the semi-open range [0.0..1.0). |
|||
<syntaxhighlight lang="algol68"> |
|||
BEGIN # sleeping beauty problem - translated from the Wren sample # |
|||
PROC sleeping beauty = ( INT reps )REAL: |
|||
BEGIN |
|||
INT wakings := 0, heads := 0; |
|||
FOR i TO reps DO |
|||
wakings +:= 1; |
|||
IF next random < 0.5 THEN # [0..0.5) = heads, [0.5..1.0) = tails say # |
|||
heads +:= 1 |
|||
ELSE |
|||
wakings +:= 1 |
|||
FI |
|||
OD; |
|||
print( ( "Wakings over ", whole( reps, 0 ), " repetitions = ", whole( wakings, 0 ), newline ) ); |
|||
( heads / wakings ) * 100 |
|||
END; # sleeping beauty # |
|||
REAL pc = sleeping beauty( 1 000 000 ); |
|||
print( ( "Percentage probability of heads on waking = ", fixed( pc, -10, 6 ), "%", newline ) ) |
|||
END |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
Wakings over 1000000 repetitions = 1499978 |
|||
Percentage probability of heads on waking = 33.335289%</pre> |
|||
=={{header|Arturo}}== |
=={{header|Arturo}}== |