Skip to content

Instantly share code, notes, and snippets.

@rsakamot
Last active May 7, 2016 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsakamot/876bd7dc1f32f559000bd1107a22788c to your computer and use it in GitHub Desktop.
Save rsakamot/876bd7dc1f32f559000bd1107a22788c to your computer and use it in GitHub Desktop.
monty fall with python
import random
import click
@click.command()
@click.option('--count', default=10000, help='tying count')
@click.option('--doors_number', default=3, help='number of doors')
def simulate(count, doors_number):
doors = ''
for i in range(doors_number):
doors += str(i)
candidate = set(doors)
correct1 = 0
correct2 = 0
for i in range(count):
you_first = set(random.choice(doors))
ans = set(random.choice(doors))
if ans == you_first:
correct1 += 1
continue
# moderator open doors
moderator = candidate - you_first - ans
# re-select
you_second = candidate - you_first - moderator
#print("doors: {}\nyou_first: {}\nans: {}\nmoderator: {}\nyou_second: {}\n"\
# .format(doors,you_first,ans,moderator,you_second))
if ans == you_second:
correct2 += 1
print("if you do not re-select your answer : {}".format(correct1/count))
print("if you do re-select your answer : {}".format(correct2/count))
def main():
simulate()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment