Monty Python Paradox

I had long thought the Monty Python paradox was simply incorrect. The background of the problem is as follows,

 
“Suppose you’re on a game show, and you’re given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what’s behind the doors, opens another door, say No. 3, which has a goat. He then says to you, “Do you want to pick door No. 2?” Is it to your advantage to switch your choice?”
 
As I usually don’t just believe things that don’t make sense to me without a level of proof, I realized I should just code this, but never took the time (I’m not a full time coder, so its a science project.)

After writing the code, and running the iterations thousands of times, I have started to view the problem differently and can agree that the correct option is to swap.

This became apparent in the code, as the options to the host in terms of options differ depending on if you had picked the Car or the Goat. (I think I coded it as “Cow”), if you had picked the Car initially, the host can pick either door and open it. However, if you had picked the Goat, the host can only choose one of the two available doors (assuming they would never pick the Car, which is as the problem is stated).

PS C:\Scripts> python.exe .\paradox.py
total times you stayed : 1000 total times you won 332
total times you swapped : 1000 total times you won 671
PS C:\Scripts> python.exe .\paradox.py
total times you stayed : 1000 total times you won 327
total times you swapped : 1000 total times you won 650
PS C:\Scripts> python.exe .\paradox.py
total times you stayed : 1000 total times you won 301
total times you swapped : 1000 total times you won 667
PS C:\Scripts> python.exe .\paradox.py
total times you stayed : 1000 total times you won 345
total times you swapped : 1000 total times you won 656
PS C:\Scripts> python.exe .\paradox.py
total times you stayed : 1000 total times you won 342
total times you swapped : 1000 total times you won 658
PS C:\Scripts> python.exe .\paradox.py
total times you stayed : 1000 total times you won 324
total times you swapped : 1000 total times you won 681
PS C:\Scripts> python.exe .\paradox.py
total times you stayed : 1000 total times you won 337
total times you swapped : 1000 total times you won 693
PS C:\Scripts> python.exe .\paradox.py
total times you stayed : 100000 total times you won 33339
total times you swapped : 100000 total times you won 66431
PS C:\Scripts>


#
# High order logic : Assign 2 cows and a car to 3 doors randomly.
# A user chooses a door.
# Regardless of what is behind that door, the host will open a door containing a cow. 
# There will then be 2 doors, one with a cow, one with a car.
# There will be two seperate passes, one for switch, one for keep.
# Based on that the user will win if he gets a car. 
# A variable will keep track of the number of wins "WinPass" and "WinKeep"
# Also for validation a counter for how many runs "TurnCounterPass" and "TurnCounterKeep" 
#

import random

# door : List of what is behind what
# carDoor : the door which the car is behind
# choice1 : the door you chose. Random.
# hostOptions: the viable doors for host to choose from (cant open a car...)
# hostOpensDoor : The door the host opens
# doorlist : unassigned doors, neither selected nor opened. 

totalCountKeep= 0
totalWinKeep = 0
totalCountSwap = 0
totalWinSwap =0

def initializeDoors():
	# Initialize Doors. To start we will make everything a Cow (it makes the logic easier), and then assign a car to a random door
	global door
	global carDoor
	door=["Cow", "Cow", "Cow"]
	##print(door)

	# Now we will assign a car to a random door  
	door[random.randint(1,3)-1]= "Car"
	
	carDoor=door.index("Car")+1
	
def makeChoice():
	global doorlist
	global choice1
	doorlist=[1,2,3]
	choice1=random.randint(1,3)
	doorlist.remove(choice1)
	return choice1, doorlist
	
def hostOpens():
	global HostOpensDoor
	if choice1==carDoor:
		#print("You chose the carDoor we have to radomize",doorlist)
		hostOptions=random.randint(1,2)
		HostOpensDoor=doorlist[hostOptions-1]
		#print ("Host Opens Door",HostOpensDoor,"Door ",HostOpensDoor," is ",door[HostOpensDoor-1])
		doorlist.remove(HostOpensDoor)
		#print("Remaining Door", doorlist)
	else:

		option1=doorlist[0]
		if option1 == carDoor:
			hostOptions=doorlist[1]
		else:
			hostOptions=doorlist[0]
		#print("doorlist pre hostlist is :",doorlist)

		HostOpensDoor=hostOptions
		#print("you did not choose car on first choice doors are now",hostOptions)
		#print("The Game Show Host can only choose from door ",hostOptions)
		#print ("Host Opens Door",HostOpensDoor,"Door ",HostOpensDoor," is ",door[HostOpensDoor-1])
		doorlist.remove(HostOpensDoor)
		#print("Remaining Door", doorlist)
		#print()
		
def keepChoice():
	global choice2
	global totalCountKeep
	global totalWinKeep
	global result
	totalCountKeep = totalCountKeep + 1
	choice2=choice1
	if choice2==carDoor:
		result = "You Win"
		totalWinKeep = totalWinKeep+ 1
	else:
		result = "You Lost"
	

def swap():
	global choice2
	global totalCountSwap
	global totalWinSwap
	global result
	totalCountSwap= totalCountSwap+1
	choice2=doorlist[0]
	if choice2==carDoor:
		result = "You Win"
		totalWinSwap = totalWinSwap+ 1
	else:
		result = "You Lost"
	

for x in range(0, 100000):
	initializeDoors()
	makeChoice()
	hostOpens()
	keepChoice()
	
for y in range(0, 100000):

	initializeDoors()
	makeChoice()
	hostOpens()
	swap()
		
print ("total times you stayed : ", totalCountKeep," total times you won ", totalWinKeep)
print ("total times you swapped : ", totalCountSwap," total times you won ", totalWinSwap)
#print ("The doors are loaded as ",door)
#print ("you first chose door:",choice1)
#print("Car is beind door",carDoor)
#print("host opened door :", HostOpensDoor)
#print("You then chose door: ", choice2)
#print("the Result is:",result)

Leave a comment