Mountebank

Temtem SV distribution script

Mar 10th, 2020
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. from pprint import pprint
  2. from collections import defaultdict
  3.  
  4. # Number of stats
  5. STATS = 7
  6.  
  7. # Max SV value
  8. MAX_SV = 50
  9.  
  10. # Minimum total SVs
  11. MIN_TOTAL_SVS = 168
  12.  
  13. def calc_distribution():
  14.     # distribution[(n, k)] = number of ways to get total svs n with exactly k perfect svs
  15.     distribution = {(0, 0): 1}
  16.     for stat in range(STATS):
  17.         new_distribution = defaultdict(int)
  18.         for sv_sum, num_perfect in distribution:
  19.             for sv in range(1, MAX_SV+1):
  20.                 new_sum = sv_sum + sv
  21.                 new_perfect = num_perfect + (sv == MAX_SV)
  22.                 new_distribution[new_sum, new_perfect] += distribution[sv_sum, num_perfect]
  23.         distribution = new_distribution
  24.     return distribution
  25.  
  26. # Reduce on perfect_sv count given that sv_sum >= min_sv_sum
  27. # Returns map of perfect_svs -> number of ways that this can be generated.
  28. def reduce_distribution(d, min_sv_sum):
  29.     distribution = defaultdict(int)
  30.     for sv_sum, num_perfect in d:
  31.         if sv_sum < min_sv_sum:
  32.             continue
  33.         distribution[num_perfect] += d[sv_sum, num_perfect]
  34.     return distribution
  35.  
  36. def main():
  37.     distribution = calc_distribution()
  38.     x = reduce_distribution(distribution, MIN_TOTAL_SVS)
  39.     pprint(dict(x))
  40.     print "Total: %d" % sum(x.values())
  41.     print "Probability of 1+ perfect SV: %f" % (float(sum(x.values()) - x[0]) / sum(x.values()))
  42.  
  43.  
  44. if __name__ == '__main__':
  45.     main()
Advertisement
Add Comment
Please, Sign In to add comment