Advertisement
WarPie90

Untitled

Jul 27th, 2023
1,742
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.07 KB | None | 0 0
  1. program new;
  2. {$I SRL/utils.simba}
  3.  
  4. procedure TStringArray.Scramble();
  5. var i: Int32;
  6. begin
  7.   for i:=0 to High(self) do
  8.     Swap(Self[i], Self[Random(Length(self))]);
  9. end;
  10.  
  11. var
  12.   doors: TStringArray = ['empty', 'empty', 'CAR'];
  13.   available: TIntegerArray;
  14.   i, w, empty, door: Int32;
  15. begin
  16.   doors.Scramble(); // randomize doors
  17.  
  18.   for i:=0 to 10000 do
  19.   begin
  20.     available := [0,1,2]; // the avilable doors
  21.  
  22.     // person: make a selection of 1 in 3 doors
  23.     door := Random(3);
  24.  
  25.     // hostmaster removes a knowingly empty door that is also not equal
  26.     // to your choice.
  27.     empty := Random(3);
  28.     while (empty = door) or (doors[empty] = 'CAR') do empty := Random(3);
  29.     available.Remove(empty);
  30.  
  31.     //person: switch door!!
  32.     if True then
  33.     begin
  34.       available.Remove(door); // se we remove the old selection
  35.       door := available[0];   // only one door left now.
  36.     end;
  37.  
  38.     // does it contain the car?
  39.     if doors[door] = 'CAR' then
  40.       inc(w);
  41.  
  42.     doors.Scramble(); // rescramble and repeat
  43.   end;
  44.  
  45.   WriteLn(w / i);
  46. end.
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement