Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
32
Task/Sleeping-Beauty-problem/Ada/sleeping-beauty-problem.ada
Normal file
32
Task/Sleeping-Beauty-problem/Ada/sleeping-beauty-problem.ada
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
with Ada.Numerics.Discrete_Random;
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure Sleeping_Beauty is
|
||||
type Coin is (Heads, Tails);
|
||||
package Random_Coin is new Ada.Numerics.Discrete_Random (Coin); use Random_Coin;
|
||||
package FIO is new Float_IO (Float);
|
||||
Tosser : Generator;
|
||||
Probability : Float;
|
||||
|
||||
function Experiment (Tosses : Integer) return Float is
|
||||
Awakenings, Heads_Count : Integer := 0;
|
||||
begin
|
||||
for Iteration in 1 .. Tosses loop
|
||||
case Random (Tosser) is
|
||||
when Heads =>
|
||||
Awakenings := Awakenings + 1;
|
||||
Heads_Count := Heads_Count + 1;
|
||||
when Tails =>
|
||||
Awakenings := Awakenings + 2;
|
||||
end case;
|
||||
end loop;
|
||||
Put_Line ("Awakenings over" & Tosses'Image & " iterations:" & Awakenings'Image);
|
||||
return Float (Heads_Count) / Float (Awakenings) * 100.0;
|
||||
end Experiment;
|
||||
|
||||
begin
|
||||
Reset (Tosser);
|
||||
Probability := Experiment (1_000_000);
|
||||
Put ("Percentage probability of heads on waking:");
|
||||
FIO.Put (Probability, 3, 5, 0);
|
||||
end Sleeping_Beauty;
|
||||
Loading…
Add table
Add a link
Reference in a new issue