entry #1
comments 0
Notes_260304_012825.sdocx data
started at ; stage 2 since . guess by
now I know my probabilities, next time won't you guess with me? explain the monty hall problem. submissions may be written in any language.
the monty hall problem is a well-known probability question with a result many find unintuitive. here's how it goes.
imagine you're on a game show where you have the chance to win a car. the host presents to you 3 doors and tells you that behind one of the doors is a car; behind the other two, goats. she invites you to pick a door, and you pick one – let's say you pick the first one. the host, who knows the location of the car, opens another door with a goat behind it – in this case, door number 2. she tells you, "whatever's behind your door, door #1, is yours to keep if you open it now. but you can also choose to swap and open the other door, door #3, instead. you can only open one of them." which door should you choose? does it matter?
the answer to this puzzle is that you should always swap and open the other door. in this example, there is a ⅔ chance that door #3 has a car behind it.
but why? your challenge is to demonstrate the solution to this problem programmatically, via any way or how. as any language is allowed, and this problem is open-ended, there is no fixed API.
you can download all the entries
comments 0
Notes_260304_012825.sdocx data
comments 0
post a comment
entry.tar.gz gzip compressed data, from Atari
1cg: couldn't decode file contents
comments 0
post a comment
Scratch Project (2).sb3 data
comments 0
post a comment
vibecode.txt ASCII text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Sure! Here's a simple Python program that uses a simulation to prove the solution to the Monty Hall problem.
import random
#This function simuates the Monty Hall problem for a number of trials given by the input variable numTrials.
#It returns two variables, stayWin and switchWin, for the amount of times the player would win by staying with the original choice and the number of the times the player would win by switching their chosen door.
def montyHallSimulation(numTrials):
stayWin = 0
switchWin = 0
for _ in range(numTrials):
#Step 1
#For each simulation, one of the three doors is picked to be the one containing the car using the random module.
carDoor = random.randint(1,3)
#Step 2
#The door that is the contestant's first choice is also randomly picked.
choiceDoor = random.randint(1,3)
#Step 3
#Checking the two doors that were not initally picked by the contestant in a random order, we find one of the two that contains a goat to reveal.
#The third door is the remaining one that the contestant has the choice to switch to.
checkDoors = [1,2,3]
checkDoors.remove(choiceDoor)
random.shuffle(checkDoors)
if checkDoors[0] != carDoor:
goatDoor = checkDoors[0]
remainingDoor = checkDoors[1]
else:
goatDoor = checkDoors[1]
remainingDoor = checkDoors[0]
#Step 4
#Given the contestant's initial chosen door and the third remaining door, we assign a point to one of our two variables based on what options would lead them to win.
if carDoor == choiceDoor:
stayWin += 1
if carDoor == remainingDoor:
switchWin += 1
#When the loop is done running for each of the trials, we return our two variables as the final result.
return (stayWin, switchWin)
#Here we run our function to simulate 1000 trials.
numTrials = 1000
stayWin, switchWin = montyHallSimulation(numTrials)
print(f"For {numTrials} trials of the Monty Hall problem:")
print(f"The correct choice was to stay {stayWin} times, or {stayWin / numTrials * 100}% of the time.")
print(f"The correct choice was to switch {switchWin} times, or {switchWin / numTrials * 100}% of the time.")
Try running this code. We should expect to see that switching doors is the correct choice about two thirds of time, or 66.67%.
Does this help you understand the Monty Hall problem?
post a comment