Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -5,3 +5,6 @@ Run random simulations of the [[wp:Monty_Hall_problem|Monty Hall]] game. Show th
|
|||
Note that the player may initially choose any of the three doors (not just Door 1), that the host opens a different door revealing a goat (not necessarily Door 3), and that he gives the player a second choice between the two remaining unopened doors.
|
||||
|
||||
Simulate at least a thousand games using three doors for each strategy <u>and show the results</u> in such a way as to make it easy to compare the effects of each strategy.
|
||||
|
||||
;Reference:
|
||||
* [https://www.youtube.com/watch?v=4Lb-6rxZxx0 Monty Hall Problem - Numberphile]. (Video).
|
||||
|
|
|
|||
33
Task/Monty-Hall-problem/Python/monty-hall-problem-2.py
Normal file
33
Task/Monty-Hall-problem/Python/monty-hall-problem-2.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import random
|
||||
#1 represents a car
|
||||
#0 represent a goat
|
||||
|
||||
stay = 0 #amount won if stay in the same position
|
||||
switch = 0 # amount won if you switch
|
||||
|
||||
for i in range(1000):
|
||||
lst = [1,0,0] # one car and two goats
|
||||
random.shuffle(lst) # shuffles the list randomly
|
||||
|
||||
ran = random.randrange(3) # gets a random number for the random guess
|
||||
|
||||
user = lst[ran] #storing the random guess
|
||||
|
||||
del(lst[ran]) # deleting the random guess
|
||||
|
||||
huh = 0
|
||||
for i in lst: # getting a value 0 and deleting it
|
||||
if i ==0:
|
||||
del(lst[huh]) # deletes a goat when it finds it
|
||||
break
|
||||
huh+=1
|
||||
|
||||
if user ==1: # if the original choice is 1 then stay adds 1
|
||||
stay+=1
|
||||
|
||||
if lst[0] == 1: # if the switched value is 1 then switch adds 1
|
||||
switch+=1
|
||||
|
||||
print("Stay =",stay)
|
||||
print("Switch = ",switch)
|
||||
#Done by Sam Witton 09/04/2014
|
||||
38
Task/Monty-Hall-problem/Scilab/monty-hall-problem.scilab
Normal file
38
Task/Monty-Hall-problem/Scilab/monty-hall-problem.scilab
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// How it works:
|
||||
// MontyHall() is a function with argument switch:
|
||||
// it will be called 100000 times with switch=%T,
|
||||
// and another 100000 times with switch=%F
|
||||
|
||||
function win=MontyHall(switch) //If switch==%T the player will switch
|
||||
doors=zeros(1,3) //All goats
|
||||
car=grand(1,1,'uin',1,3)
|
||||
a(car)=1 //Place a car somewher
|
||||
pick=grand(1,1,'uin',1,3) //The player picks...
|
||||
if pick==car then //If the player picks right...
|
||||
if switch==%T then //...and switches he will be wrong
|
||||
win=%F
|
||||
else //...but if he doesn't, he will be right
|
||||
win=%T
|
||||
end
|
||||
else //If the player picks a goat...
|
||||
if switch==%T then //...and switches: the other door with the goat shall be
|
||||
win=%T // opened: the player will switch to the car and win
|
||||
else //...but if he doesn't, he will remain by his goat
|
||||
win=%F
|
||||
end
|
||||
end
|
||||
endfunction
|
||||
|
||||
wins_switch=0
|
||||
wins_stay=0
|
||||
games=100000
|
||||
for i=1:games
|
||||
if MontyHall(%T)==%T then
|
||||
wins_switch=wins_switch+1
|
||||
end
|
||||
if MontyHall(%F)==%T then
|
||||
wins_stay=wins_stay+1
|
||||
end
|
||||
end
|
||||
disp("Switching, one wins"+ascii(10)+string(wins_switch)+" games out of "+string(games))
|
||||
disp("Staying, one wins"+ascii(10)+string(wins_stay)+" games out of "+string(games))
|
||||
Loading…
Add table
Add a link
Reference in a new issue