Advertisement
Guest User

Untitled

a guest
May 9th, 2020
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. import numpy as np
  2.  
  3. class EllysTwoRatings:
  4.     def getChance(self, N, A, B):
  5.         dist = np.zeros((1001, 1001), dtype=np.float)
  6.         dist[A][B] = 1.0
  7.  
  8.         mn = np.maximum(1, np.arange(1001) - 100)
  9.         mx = np.minimum(1000, np.arange(1001) + 100)
  10.         denoms = mx - mn + 1
  11.  
  12.         ans = 0.0
  13.         for n in range(N):
  14.             for i in range(2):
  15.                 cumDist = np.cumsum(dist.T / denoms, axis=1)
  16.                 for a in range(1, 1000 + 1):
  17.                     dist[a] = cumDist[a][mx] - cumDist[a][mn - 1]
  18.                     ans += dist[a][a]
  19.                     dist[a][a] = 0.0
  20.         return ans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement