Advertisement
toastedstapler

lobsterfishing

Aug 16th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.57 KB | None | 0 0
  1. import random
  2. import math
  3. import os
  4. import time
  5. import pylab as py
  6. import numpy as np
  7.  
  8. start = time.time()
  9. randomtests = False
  10. nooftests = 10000
  11. count = 0
  12. results = []
  13. tests = []
  14. averages = []
  15.  
  16. def order():
  17.     inshore, check = actualpots((1.0-perc) * pots) 
  18.     offshore, checkk = actualpots(perc * pots)
  19.     if check == True:
  20.         if offshore > 0:
  21.             offshore -= 1
  22.     return inshore, offshore
  23.  
  24. def actualpots(x):
  25.     num = x
  26.     while num > 1:
  27.         num -= 1
  28.     if num == 0.5:
  29.         return int(math.ceil(x)), True
  30.     elif num > 0.5:
  31.         return int(math.ceil(x)), False
  32.     else:
  33.         return int(math.floor(x)), False
  34.  
  35. if randomtests:
  36.     for q in range(nooftests):
  37.         if (q+1) % 10 == 0:
  38.             print("test number {:>4}".format(str(q+1).rjust(4)))
  39.         results.append([])
  40.         tests = []
  41.         if randomtests == True:
  42.             for x in range(10):
  43.                 tests.append(random.randrange(0, 3))
  44.         perc = 0.0
  45.         for x in range(101):
  46.             pots = 5
  47.             money = 50
  48.             for y in tests:
  49.                 inshore, offshore = order()
  50.                 if y > 0:
  51.                     money += (6 * offshore) + (2 * inshore)
  52.                 else:
  53.                     money += (4 * inshore)
  54.                     pots = inshore
  55.                 pots += (money // 5)
  56.                 money = (money % 5)
  57.             results[q].append(money + (5 * pots))
  58.             perc += 0.01
  59.  
  60. else:
  61.     nooftests = 1024
  62.     for x in range(1024):
  63.         tests.append(str(bin(x))[2:].rjust(10, "0"))
  64.     for q in range(len(tests)):
  65.         results.append([])
  66.         if (q+1) % 10 == 0 or (q+1) == nooftests:
  67.             print("test number", str(q+1).rjust(4))
  68.         perc = 0.00
  69.         for x in range(101):
  70.             pots = 5
  71.             money = 50
  72.             for t in tests[q]:
  73.                 inshore, offshore = order()
  74.                 if t == "1":
  75.                     money += (2 * inshore) + (6 * offshore)
  76.                 else:
  77.                     money += (4 * inshore)
  78.                     pots = inshore
  79.                 pots += (money // 5)
  80.                 money = (money % 5)
  81.             for e in range(2**tests[q].count("1")):
  82.                 results[q].append(money + (pots * 5))
  83.             perc += 0.01
  84.  
  85. print("\n")
  86.  
  87. if randomtests:
  88.     print("other test")
  89.     total = 0
  90.     for y in range(101):
  91.         total = 0
  92.         for x in range(len(results)):
  93.             total += results[x][y]
  94.         averages.append(total/nooftests)
  95. else:
  96.     print("59049 test")
  97.     datacopy = results.copy()
  98.     averages = []
  99.     for y in range(101):
  100.         print("averaging at {:>3}%".format(y))
  101.         total = 0
  102.         for x in range(len(datacopy)):
  103.             for q in range(2**bin(x)[2:].count("1")):
  104.                 total += datacopy[x].pop(0)
  105.         averages.append(total/59049)
  106.  
  107. xc = py.arange(0, 101, 1)
  108. yc = np.array(averages)
  109. py.plot(xc, yc)
  110. py.xlabel("% of pots offshore")
  111. py.ylabel("expected return value")
  112. print("that took {} minutes and {} seconds".format(
  113.     int(time.time() - start) // 60, int(time.time() - start) % 60))
  114. py.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement