Skip to content

Instantly share code, notes, and snippets.

@arisada
Last active June 2, 2020 15:53
Show Gist options
  • Select an option

  • Save arisada/64104411bf762597de9441d2039bfdb7 to your computer and use it in GitHub Desktop.

Select an option

Save arisada/64104411bf762597de9441d2039bfdb7 to your computer and use it in GitHub Desktop.

Revisions

  1. arisada revised this gist Jun 2, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion montyhall.py
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    import random

    change_strategy, stay_strategy = 0, 0
    for i in range(1):
    for i in range(1000):
    v = [True, False, False]
    random.shuffle(v)
    print("Solution:", v)
  2. arisada created this gist Jun 2, 2020.
    27 changes: 27 additions & 0 deletions montyhall.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/usr/bin/env python3

    import random

    change_strategy, stay_strategy = 0, 0
    for i in range(1):
    v = [True, False, False]
    random.shuffle(v)
    print("Solution:", v)
    firstchoice = random.choice([0, 1, 2])
    print("First choice", firstchoice)
    others = [i for i in [0, 1, 2] if i != firstchoice]
    if v[firstchoice]:
    closed = random.choice(others)
    else:
    closed = others[1] if v[others[0]] else others[0]
    print("closing", closed)

    if v[firstchoice]:
    print("Stay wins")
    stay_strategy += 1
    remaining_choices = [i for i in [0, 1, 2] if i != firstchoice and i != closed]
    if v[remaining_choices[0]]:
    print("Change wins")
    change_strategy +=1

    print(change_strategy, stay_strategy)