Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program new;
- {$I SRL/utils.simba}
- procedure TStringArray.Scramble();
- var i: Int32;
- begin
- for i:=0 to High(self) do
- Swap(Self[i], Self[Random(Length(self))]);
- end;
- var
- doors: TStringArray = ['empty', 'empty', 'CAR'];
- available: TIntegerArray;
- i, w, empty, door: Int32;
- begin
- doors.Scramble(); // randomize doors
- for i:=0 to 10000 do
- begin
- available := [0,1,2]; // the avilable doors
- // person: make a selection of 1 in 3 doors
- door := Random(3);
- // hostmaster removes a knowingly empty door that is also not equal
- // to your choice.
- empty := Random(3);
- while (empty = door) or (doors[empty] = 'CAR') do empty := Random(3);
- available.Remove(empty);
- //person: switch door!!
- if True then
- begin
- available.Remove(door); // se we remove the old selection
- door := available[0]; // only one door left now.
- end;
- // does it contain the car?
- if doors[door] = 'CAR' then
- inc(w);
- doors.Scramble(); // rescramble and repeat
- end;
- WriteLn(w / i);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement