program Project1;
type Gender = (Female, Male);
type Child = record
g : Gender;
dw : integer;
end;
type Farmer = record
c : array [0..1] of Child;
end;
procedure GenerateChild (var c : Child);
begin
if random(2)=0 then c.g := Female else c.g := Male;
c.dw := random(7);
end;
type FarmerAnswer = record
goc : Gender;
dwoc : integer;
end;
procedure GenerateFarmer(var f: Farmer);
begin
GenerateChild (f.c[0]);
GenerateChild (f.c[1]);
end;
procedure GetAnswer (const F : Farmer; var FA : FarmerAnswer);
var
ci : integer;
begin
if (F.c[0].g = Male) and (F.c[1].g = Female) then
ci := 0
else if (F.c[0].g = Female) and (F.c[1].g = Male) then
ci := 1 // ÷òîáû 1/3 ïîëó÷èòü - âûáèðàåì èìåííî ñûíà
else
ci := random(2);
FA.goc := F.c[ci].g;
FA.dwoc := F.c[ci].dw;
end;
var
i : integer;
F : Farmer;
FA : FarmerAnswer;
Count, Success : integer;
begin
Randomize;
Count := 0;
Success := 0;
for i := 0 to 1000*1000-1 do begin
GenerateFarmer(F);
GetAnswer(F, FA);
if (FA.goc=Male) and (FA.dwoc=1) then begin
Inc(Count);
if (F.c[0].g = Male) and (F.c[1].g = Male) then
Inc(Success);
end;
end;
WriteLn('Count=', Count, '; Success=', Success, '; Ratio=', Success/Count:0:10);
end.
cHJvZ3JhbSBQcm9qZWN0MTsKCnR5cGUgR2VuZGVyID0gKEZlbWFsZSwgTWFsZSk7Cgp0eXBlIENoaWxkID0gcmVjb3JkCiAgZyAgOiBHZW5kZXI7CiAgZHcgOiBpbnRlZ2VyOwplbmQ7Cgp0eXBlIEZhcm1lciA9IHJlY29yZAogIGMgOiBhcnJheSBbMC4uMV0gb2YgQ2hpbGQ7CmVuZDsKCnByb2NlZHVyZSBHZW5lcmF0ZUNoaWxkICh2YXIgYyA6IENoaWxkKTsKYmVnaW4KICBpZiByYW5kb20oMik9MCB0aGVuIGMuZyA6PSBGZW1hbGUgZWxzZSBjLmcgOj0gTWFsZTsKICBjLmR3IDo9IHJhbmRvbSg3KTsKZW5kOwoK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