def multiplierGen(n = 0): while True: if n == 0: yield 1 else: yield fact(2 * n) / (fact(n) * fact(n + 1)) n += 1
def getRoutes(n): # Work out the row row = n * 2 # Get mid point of row midpoint = n return fact(row) / (fact(midpoint)**2)
def challenge053(): count = 0 for n in xrange(1, 101): for r in xrange(n, 0, -1): combinations = fact(n) / (fact(r) * fact(n - r)) if combinations > 1000000: count += 1 return count
def permutations(digits): prevI = -1 nI = 0 quantities = fact(len(digits)) factors = 1 for i in digits: if i == prevI: nI += 1 else: factors *= fact(nI) prevI = i nI = 1 factors *= fact(nI) return quantities // factors
def getLimit(): factSum = 0 factNine = fact(9) digits = 1 while True: digits *= 10 factSum += factNine print digits, factSum if factSum < digits: break return factSum
def play(turns): den = fact(turns + 1) lossesAllowed = turns // 2 if not (turns & 1): lossesAllowed -= 1 chances = 0 probs = range(2, turns + 2) for losses in xrange(lossesAllowed + 1): wc = winChance(probs, losses) chances += wc prize = den // chances return prize