program Project1;
type Gender = (Female, Male);
type Farmer = record
Child1, Child2 : Gender;
end;
type FarmerAnswer = (IHaveADaughter, IHaveASon);
function GenerateFarmer : Farmer;
var
FuckStupidGPC : Farmer;
begin
if random(2)=0 then FuckStupidGPC.Child1 := Female
else FuckStupidGPC.Child1 := Male;
if random(2)=0 then FuckStupidGPC.Child2 := Female
else FuckStupidGPC.Child2 := Male;
GenerateFarmer := FuckStupidGPC;
end;
function GetAnswer (const F : Farmer) : FarmerAnswer;
var
FuckStupidGPC : FarmerAnswer;
begin
if random(2)=0 then begin
if F.Child1 = Female then FuckStupidGPC := IHaveADaughter
else FuckStupidGPC := IHaveASon;
end else begin
if F.Child2 = Female then FuckStupidGPC := IHaveADaughter
else FuckStupidGPC := IHaveASon;
end;
GetAnswer := FuckStupidGPC;
end;
var
i : integer;
F : Farmer;
FA : FarmerAnswer;
Count, Success : integer;
begin
Randomize;
Count := 0;
Success := 0;
for i := 0 to 1000*1000*10-1 do begin
F := GenerateFarmer;
FA := GetAnswer(F);
if FA=IHaveASon then begin
Inc(Count);
if (F.Child1 = Male) and (F.Child2 = Male) then
Inc(Success);
end;
end;
WriteLn('Count=', Count, '; Success=', Success, '; Ratio=', Success/Count:0:10);
end.
cHJvZ3JhbSBQcm9qZWN0MTsKCnR5cGUgR2VuZGVyID0gKEZlbWFsZSwgTWFsZSk7Cgp0eXBlIEZhcm1lciA9IHJlY29yZAogIENoaWxkMSwgQ2hpbGQyIDogR2VuZGVyOwplbmQ7Cgp0eXBlIEZhcm1lckFuc3dlciA9IChJSGF2ZUFEYXVnaHRlciwgSUhhdmVBU29uKTsKCmZ1bmN0aW9uIEdlbmVyYXRlRmFybWVyIDogRmFybWVyOwp2YXIKICBGdWNrU3R1cGlkR1BDIDogRmFybWVyOwpiZWdpbgogIGlmIHJhbmRvbSgyKT0wIHRoZW4gRnVja1N0dXBpZEdQQy5DaGlsZDEgOj0gRmVtYWxlCiAgZWxzZSBGdWNrU3R1cGlkR1BDLkNoaWxkM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