fork(1) download
  1. program Project1;
  2.  
  3. type Gender = (Female, Male);
  4.  
  5. type Farmer = record
  6. Child1, Child2 : Gender;
  7. end;
  8.  
  9. type FarmerAnswer = (IHaveADaughter, IHaveASon);
  10.  
  11. function GenerateFarmer : Farmer;
  12. var
  13. FuckStupidGPC : Farmer;
  14. begin
  15. if random(2)=0 then FuckStupidGPC.Child1 := Female
  16. else FuckStupidGPC.Child1 := Male;
  17.  
  18. if random(2)=0 then FuckStupidGPC.Child2 := Female
  19. else FuckStupidGPC.Child2 := Male;
  20.  
  21. GenerateFarmer := FuckStupidGPC;
  22. end;
  23.  
  24. function GetAnswer (const F : Farmer) : FarmerAnswer;
  25. var
  26. FuckStupidGPC : FarmerAnswer;
  27. begin
  28. if random(2)=0 then begin
  29. if F.Child1 = Female then FuckStupidGPC := IHaveADaughter
  30. else FuckStupidGPC := IHaveASon;
  31. end else begin
  32. if F.Child2 = Female then FuckStupidGPC := IHaveADaughter
  33. else FuckStupidGPC := IHaveASon;
  34. end;
  35.  
  36. GetAnswer := FuckStupidGPC;
  37. end;
  38.  
  39. var
  40. i : integer;
  41. F : Farmer;
  42. FA : FarmerAnswer;
  43. Count, Success : integer;
  44. begin
  45. Randomize;
  46. Count := 0;
  47. Success := 0;
  48. for i := 0 to 1000*1000*10-1 do begin
  49. F := GenerateFarmer;
  50. FA := GetAnswer(F);
  51. if FA=IHaveASon then begin
  52. Inc(Count);
  53. if (F.Child1 = Male) and (F.Child2 = Male) then
  54. Inc(Success);
  55. end;
  56. end;
  57.  
  58. WriteLn('Count=', Count, '; Success=', Success, '; Ratio=', Success/Count:0:10);
  59. end.
  60.  
Success #stdin #stdout 3.34s 2004KB
stdin
Standard input is empty
stdout
Count=4999804; Success=2497498; Ratio=0.4995191812