Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import random, sys
- def play(min):
- #min = 75000 # minimum prize contestant wants to win
- prizes = [0.01, 0.1, 0.50, 1, 5, 10, 50, 100, 250, 500, 750, 1000, 3000, 5000, 10000, 15000, 20000, 35000, 50000, 75000, 100000, 250000]
- a = 21
- p = prizes.index(min) # find position of min in prizes and use this to create a list of acceptable winnings
- accept = prizes[p:]
- choice = random.randint(0,a)
- cbox = prizes.pop(choice) # value of contestant's box
- a = a-1
- while a > 0:
- if len(accept) > 1:
- sbox = prizes.pop(random.randint(0,a)) # value of selected box
- #print "sbox = " + str(sbox)
- if sbox in accept:
- accept.remove(sbox)
- a = a-1
- else:
- break
- if cbox >= min:
- return 1
- else:
- return 0
- def calculate(min):
- swap = 0
- stay = 0
- #min = raw_input("What's the minimum amount you want to win? 1000, 3000, 5000, 10000, 15000, 20000, 35000, 50000, 75000, 100000, 250000...\n")
- for i in range(1,100001):
- if play(int(min)) == 0:
- swap = swap + 1
- else:
- stay = stay + 1
- """print "### Greed = " + str(min) + " ###"
- print "Win " + str(swap) + " times if you swap"
- print "Win " + str(stay) + " times if you stay"""
- out = str(min) + "\t" + str(swap) + "\t" + str(stay)
- return out
- def main():
- prizes = [1, 5, 10, 50, 100, 250, 500, 750, 1000, 3000, 5000, 10000, 15000, 20000, 35000, 50000, 75000, 100000]
- print "Min\tSuccesses if swap\tSuccesses if stay"
- for value in prizes:
- print calculate(value)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement