new-21-game-v2.py (659B)
1 class Solution: 2 3 def new21Game(self, n: int, k: int, maxPts: int) -> float: 4 5 # while less than k she draws 6 # stops when she has k or more points 7 # return probability that alice has n or fewer points 8 9 probabilities = [1.00] 10 11 jump_prob = 1 / maxPts 12 13 for i in range(0, k): 14 current_prob = probabilities[i] 15 for x in range(1,maxPts + 1): 16 if len(probabilities) < i + x + 1: 17 probabilities.append(0) 18 probabilities[i+x] += jump_prob * current_prob 19 20 print(probabilities) 21 22 return 1 - sum(probabilities[n + 1:])