TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

My take on the Monty Hall problem

1 pointsby nikola_virtualover 1 year ago
When I first encountered the Monty Hall problem, my initial reaction was to understand the host&#x27;s strategy and motivation. However, I noticed that this aspect is often overlooked in discussions, with most people focusing solely on the mathematical probabilities.<p>To delve deeper into the problem, I decided to write a code implementation that reflects my perspective. By simulating the scenario, I aimed to gain a clearer understanding of the host&#x27;s role and its impact on the outcome.<p>Here&#x27;s the code I developed to explore this perspective:<p>```<p>import random<p>def monty_hall_simulation():<p><pre><code> doors = [0, 0, 1] # 0 represents a goat, 1 represents a car random.shuffle(doors) # Shuffle the doors randomly # Player makes the initial choice initial_choice = random.randint(0, 2) # Host reveals a door when the guest is right if doors[initial_choice] == 1: revealed_door = next(i for i in range(3) if i != initial_choice and doors[i] == 0) final_choice_switch = next(i for i in range(3) if i != initial_choice and i != revealed_door) else: # The host does not give the guest a chance to switch final_choice_switch = initial_choice return doors[final_choice_switch] == 1, doors[initial_choice] == 1 </code></pre> num_trials = 1000<p>switch_win_count = 0<p>stick_win_count = 0<p>for _ in range(num_trials):<p><pre><code> switch_win, stick_win = monty_hall_simulation() if switch_win: switch_win_count += 1 if stick_win: stick_win_count += 1 </code></pre> print(f&quot;Switching wins: {switch_win_count}&quot;)<p>print(f&quot;Sticking wins: {stick_win_count}&quot;)<p>```<p>In my implementation, the host understands the math and only opens another door with a goat when the guest is right. As the audience decodes the host&#x27;s strategy and uses it to their advantage, the host adapts and changes their strategy. Eventually, the probability becomes just random.<p>Previous HN discussion: https:&#x2F;&#x2F;hn.algolia.com&#x2F;?q=Monty+Hall+problem

2 comments

nikola_virtualover 1 year ago
This approach highlights the human element in the Monty Hall problem and emphasizes the importance of considering the psychological aspects alongside the mathematical analysis.
dave4420over 1 year ago
Are you saying that the host wants the contestant to lose? This does not seem to be how game show hosts behave in reality.
评论 #37970550 未加载