Advertisement
Guest User

Untitled

a guest
Mar 8th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import random, sys
  4.  
  5. def play(min):
  6.  
  7.   #min = 75000 # minimum prize contestant wants to win
  8.   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]
  9.   a = 21
  10.   p = prizes.index(min) # find position of min in prizes and use this to create a list of acceptable winnings
  11.   accept = prizes[p:]
  12.  
  13.   choice = random.randint(0,a)
  14.   cbox = prizes.pop(choice) # value of contestant's box
  15.   a = a-1
  16.  
  17.  
  18.   while a > 0:
  19.     if len(accept) > 1:
  20.       sbox = prizes.pop(random.randint(0,a)) # value of selected box
  21.       #print "sbox = " + str(sbox)
  22.       if sbox in accept:
  23.         accept.remove(sbox)
  24.       a = a-1
  25.     else:
  26.       break
  27.  
  28.   if cbox >= min:
  29.     return 1
  30.   else:
  31.     return 0
  32.  
  33. def calculate(min):
  34.   swap = 0
  35.   stay = 0
  36.  
  37.   #min = raw_input("What's the minimum amount you want to win? 1000, 3000, 5000, 10000, 15000, 20000, 35000, 50000, 75000, 100000, 250000...\n")
  38.  
  39.   for i in range(1,100001):
  40.     if play(int(min)) == 0:
  41.       swap = swap + 1
  42.     else:
  43.       stay = stay + 1
  44.        
  45.   """print "### Greed = " + str(min) + " ###"
  46.  print "Win " + str(swap) + " times if you swap"
  47.  print "Win " + str(stay) + " times if you stay"""
  48.  
  49.   out = str(min) + "\t" + str(swap) + "\t" + str(stay)
  50.   return out
  51.  
  52. def main():
  53.  
  54.   prizes = [1, 5, 10, 50, 100, 250, 500, 750, 1000, 3000, 5000, 10000, 15000, 20000, 35000, 50000, 75000, 100000]
  55.  
  56.   print "Min\tSuccesses if swap\tSuccesses if stay"
  57.  
  58.   for value in prizes:
  59.     print calculate(value)
  60.  
  61. if __name__ == "__main__":
  62.   main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement