Guest User

coverdist.py

a guest
Mar 24th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. import functools
  2.  
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5.  
  6. @functools.lru_cache(maxsize=None)
  7. def coverdist(covers, max_pulls):
  8.     result = np.zeros(max_pulls+1, dtype=np.float)
  9.     pulls = sum(covers)
  10.     a, b, c = covers
  11.     complete = min(a, 5) + min(b, 5) + min(c, 5) >= 13
  12.  
  13.     if complete:
  14.         result[pulls:] = 1.0
  15.     elif pulls < max_pulls:
  16.         result += coverdist(tuple(sorted([a+1,b,c])), max_pulls) / 3
  17.         result += coverdist(tuple(sorted([a,b+1,c])), max_pulls) / 3
  18.         result += coverdist(tuple(sorted([a,b,c+1])), max_pulls) / 3
  19.     return result
  20.  
  21. if __name__ == '__main__':
  22.     max_pulls = 35
  23.  
  24.     dist = coverdist((0,0,0), max_pulls)
  25.     plt.bar(np.arange(max_pulls+1), dist)
  26.  
  27.     dist2 = coverdist((4,1,0), max_pulls)
  28.     plt.bar(np.arange(max_pulls+1), dist2)
  29.     plt.show()
Advertisement
Add Comment
Please, Sign In to add comment