Beispiel #1
0
def compute():
    DIGITS = 100
    increasing = eulerlib.binomial(DIGITS + 9, 9) - 1
    decreasing = eulerlib.binomial(DIGITS + 10, 10) - (DIGITS + 1)
    flat = DIGITS * 9
    ans = increasing + decreasing - flat
    return str(ans)
Beispiel #2
0
def compute():
	DIGITS = 100
	increasing = eulerlib.binomial(DIGITS + 9, 9) - 1
	decreasing = eulerlib.binomial(DIGITS + 10, 10) - (DIGITS + 1)
	flat = DIGITS * 9
	ans = increasing + decreasing - flat
	return str(ans)
Beispiel #3
0
def compute():
	SET_SIZE = 12
	
	def catalan(n):
		return eulerlib.binomial(n * 2, n) // (n + 1)
	
	ans = sum(eulerlib.binomial(SET_SIZE, i * 2) * (eulerlib.binomial(i * 2, i) // 2 - catalan(i))
		for i in range(2, SET_SIZE // 2 + 1))
	return str(ans)
Beispiel #4
0
def compute():
	SET_SIZE = 12
	
	def catalan(n):
		return eulerlib.binomial(n * 2, n) // (n + 1)
	
	ans = sum(eulerlib.binomial(SET_SIZE, i * 2) * (eulerlib.binomial(i * 2, i) // 2 - catalan(i))
		for i in range(2, SET_SIZE // 2 + 1))
	return str(ans)
Beispiel #5
0
def compute():
	SIZE = 32
	DECIMALS = 10
	assert SIZE >= 0
	assert DECIMALS >= 0
	
	# Calculate the answer
	expect = [fractions.Fraction(0)]
	for n in range(1, SIZE + 1):
		temp = sum(eulerlib.binomial(n, k) * expect[k] for k in range(n))
		expect.append((2**n + temp) / (2**n - 1))
	ans = expect[-1]
	
	# Round the fraction properly. This is the pedantically
	# correct version of doing "{:.10f}".format(float(ans))
	assert ans >= 0
	scaled = ans * 10**DECIMALS
	whole = scaled.numerator // scaled.denominator
	frac = scaled - whole
	assert 0 <= frac < 1
	HALF = fractions.Fraction(1, 2)
	if frac > HALF or (frac == HALF and whole % 2 == 1):
		whole += 1
	temp = str(whole)
	if DECIMALS == 0:
		return temp
	temp = temp.zfill(DECIMALS + 1)
	return "{}.{}".format(temp[ : -DECIMALS], temp[-DECIMALS : ])
def compute():
	ans = 0
	for n in range(1, 101):
		for k in range(0, n + 1):
			if eulerlib.binomial(n, k) > 1000000:
				ans += 1
	return str(ans)
def compute():
    ans = 0
    for n in range(1, 101):
        for k in range(0, n + 1):
            if eulerlib.binomial(n, k) > 1000000:
                ans += 1
    return str(ans)
	def explore(remain, limit, history):
		if remain == 0:
			hist = list(history)
			while len(hist) < NUM_COLORS:
				hist.append(0)
			
			histogram = [0] * (BALLS_PER_COLOR + 1)
			for x in hist:
				histogram[x] += 1
			
			count = math.factorial(NUM_COLORS)
			for x in histogram:
				count = divide_exactly(count, math.factorial(x))
			
			for x in hist:
				count *= eulerlib.binomial(BALLS_PER_COLOR, x)
			
			distinctcolors = len(history)
			numerator[0] += count * distinctcolors
		
		elif len(history) < NUM_COLORS:
			for i in range(min(limit, remain), 0, -1):
				history.append(i)
				explore(remain - i, i, history)
				history.pop()
def compute():
	SIZE = 32
	DECIMALS = 10
	assert SIZE >= 0
	assert DECIMALS >= 0
	
	# Calculate the answer
	expect = [fractions.Fraction(0)]
	for n in range(1, SIZE + 1):
		temp = sum(eulerlib.binomial(n, k) * expect[k] for k in range(n))
		expect.append((2**n + temp) / (2**n - 1))
	ans = expect[-1]
	
	# Round the fraction properly. This is the pedantically
	# correct version of doing "{:.10f}".format(float(ans))
	assert ans >= 0
	scaled = ans * 10**DECIMALS
	whole = scaled.numerator // scaled.denominator
	frac = scaled - whole
	assert 0 <= frac < 1
	HALF = fractions.Fraction(1, 2)
	if frac > HALF or (frac == HALF and whole % 2 == 1):
		whole += 1
	temp = str(whole)
	if DECIMALS == 0:
		return temp
	temp = temp.zfill(DECIMALS + 1)
	return "{}.{}".format(temp[ : -DECIMALS], temp[-DECIMALS : ])
Beispiel #10
0
    def explore(remain, limit, history):
        if remain == 0:
            hist = list(history)
            while len(hist) < NUM_COLORS:
                hist.append(0)

            histogram = [0] * (BALLS_PER_COLOR + 1)
            for x in hist:
                histogram[x] += 1

            count = math.factorial(NUM_COLORS)
            for x in histogram:
                count = divide_exactly(count, math.factorial(x))

            for x in hist:
                count *= eulerlib.binomial(BALLS_PER_COLOR, x)

            distinctcolors = len(history)
            numerator[0] += count * distinctcolors

        elif len(history) < NUM_COLORS:
            for i in range(min(limit, remain), 0, -1):
                history.append(i)
                explore(remain - i, i, history)
                history.pop()
Beispiel #11
0
def compute():
    SIZE = 32
    DECIMALS = 10
    assert SIZE >= 0
    assert DECIMALS > 0

    # Calculate the answer
    expect = [fractions.Fraction(0)]
    for n in range(1, SIZE + 1):
        temp = sum(eulerlib.binomial(n, k) * expect[k] for k in range(n))
        expect.append((2**n + temp) / (2**n - 1))
    ans = expect[-1]

    # Round the fraction properly. This is the pedantically
    # correct version of doing f"{float(ans):.10f}"
    assert ans >= 0
    s = str(round(ans * 10**DECIMALS)).zfill(DECIMALS + 1)
    return f"{s[:-DECIMALS]}.{s[-DECIMALS:]}"
def compute():
    # Heuristic sampling algorithm.
    # At level 1 we test {1/2}. At level 2 we test {1/4, 3/4}.
    # At level 3 we test {1/8, 3/8, 5/8, 7/8}. Et cetera.
    TRIALS = 1000
    maxindex = -1
    prevchangelevel = 1
    level = 1
    while level - prevchangelevel <= 8:
        scaler = 0.5 ** level
        for i in range(1, 1 << level, 2):
            index = calc_billionaire_probability(i * scaler, TRIALS)
            if index > maxindex:
                maxindex = index
                prevchangelevel = level
        level += 1

        # Calculate the cumulative probability: binomialSum = sum (n choose k) for 0 <= k < maxIndex
    binomialsum = sum(eulerlib.binomial(TRIALS, i) for i in range(maxindex))
    return round_to_decimal(fractions.Fraction(binomialsum, 1 << TRIALS), 12)
def compute():
	# Collect unique numbers in Pascal's triangle
	numbers = set(eulerlib.binomial(n, k) for n in range(51) for k in range(n + 1))
	maximum = max(numbers)
	
	# Prepare list of squared primes
	primes = eulerlib.list_primes(eulerlib.sqrt(maximum))
	primessquared = [p * p for p in primes]
	
	def is_squarefree(n):
		for p2 in primessquared:
			if p2 > n:
				break
			if n % p2 == 0:
				return False
		return True
	
	# Sum up the squarefree numbers
	ans = sum(n for n in numbers if is_squarefree(n))
	return str(ans)
def compute():
    # Heuristic sampling algorithm.
    # At level 1 we test {1/2}. At level 2 we test {1/4, 3/4}.
    # At level 3 we test {1/8, 3/8, 5/8, 7/8}. Et cetera.
    TRIALS = 1000
    maxindex = -1
    prevchangelevel = 1
    level = 1
    while level - prevchangelevel <= 8:
        scaler = 0.5**level
        for i in range(1, 1 << level, 2):
            index = calc_billionaire_probability(i * scaler, TRIALS)
            if index > maxindex:
                maxindex = index
                prevchangelevel = level
        level += 1

    # Calculate the cumulative probability: binomialSum = sum (n choose k) for 0 <= k < maxIndex
    binomialsum = sum(eulerlib.binomial(TRIALS, i) for i in range(maxindex))
    return round_to_decimal(fractions.Fraction(binomialsum, 1 << TRIALS), 12)
Beispiel #15
0
def compute():
	# Collect unique numbers in Pascal's triangle
	numbers = set(eulerlib.binomial(n, k) for n in range(51) for k in range(n + 1))
	maximum = max(numbers)
	
	# Prepare list of squared primes
	primes = eulerlib.list_primes(eulerlib.sqrt(maximum))
	primessquared = [p * p for p in primes]
	
	def is_squarefree(n):
		for p2 in primessquared:
			if p2 > n:
				break
			if n % p2 == 0:
				return False
		return True
	
	# Sum up the squarefree numbers
	ans = sum(n for n in numbers if is_squarefree(n))
	return str(ans)
def compute():
	NUM_COLORS = 7
	BALLS_PER_COLOR = 10
	NUM_PICKED = 20
	DECIMALS = 9
	
	numerator = [0]
	
	def explore(remain, limit, history):
		if remain == 0:
			hist = list(history)
			while len(hist) < NUM_COLORS:
				hist.append(0)
			
			histogram = [0] * (BALLS_PER_COLOR + 1)
			for x in hist:
				histogram[x] += 1
			
			count = math.factorial(NUM_COLORS)
			for x in histogram:
				count = divide_exactly(count, math.factorial(x))
			
			for x in hist:
				count *= eulerlib.binomial(BALLS_PER_COLOR, x)
			
			distinctcolors = len(history)
			numerator[0] += count * distinctcolors
		
		elif len(history) < NUM_COLORS:
			for i in range(min(limit, remain), 0, -1):
				history.append(i)
				explore(remain - i, i, history)
				history.pop()
	
	explore(NUM_PICKED, BALLS_PER_COLOR, [])
	denominator = eulerlib.binomial(NUM_COLORS * BALLS_PER_COLOR, NUM_PICKED)
	ans = fractions.Fraction(numerator[0], denominator)
	return format_fraction(ans, DECIMALS)
Beispiel #17
0
def compute():
    NUM_COLORS = 7
    BALLS_PER_COLOR = 10
    NUM_PICKED = 20
    DECIMALS = 9

    numerator = [0]

    def explore(remain, limit, history):
        if remain == 0:
            hist = list(history)
            while len(hist) < NUM_COLORS:
                hist.append(0)

            histogram = [0] * (BALLS_PER_COLOR + 1)
            for x in hist:
                histogram[x] += 1

            count = math.factorial(NUM_COLORS)
            for x in histogram:
                count = divide_exactly(count, math.factorial(x))

            for x in hist:
                count *= eulerlib.binomial(BALLS_PER_COLOR, x)

            distinctcolors = len(history)
            numerator[0] += count * distinctcolors

        elif len(history) < NUM_COLORS:
            for i in range(min(limit, remain), 0, -1):
                history.append(i)
                explore(remain - i, i, history)
                history.pop()

    explore(NUM_PICKED, BALLS_PER_COLOR, [])
    denominator = eulerlib.binomial(NUM_COLORS * BALLS_PER_COLOR, NUM_PICKED)
    ans = fractions.Fraction(numerator[0], denominator)
    return format_fraction(ans, DECIMALS)
Beispiel #18
0
	def catalan(n):
		return eulerlib.binomial(n * 2, n) // (n + 1)
Beispiel #19
0
def p015():

    #there are exactly N moves down and N moves to the right in a NxN grid
    #there 2N choose N ways of choosing the order assuming independent moves
    return eulerlib.binomial(40, 20)
Beispiel #20
0
	def catalan(n):
		return eulerlib.binomial(n * 2, n) // (n + 1)
def compute():
	ans = sum(1
		for n in range(1, 101)
		for k in range(0, n + 1)
		if eulerlib.binomial(n, k) > 1000000)
	return str(ans)
Beispiel #22
0
def compute():
    ans = sum(1 for n in range(1, 101) for k in range(0, n + 1)
              if eulerlib.binomial(n, k) > 1000000)
    return str(ans)
Beispiel #23
0
def compute():
    return str(eulerlib.binomial(40, 20))
Beispiel #24
0
def compute():
	return str(eulerlib.binomial(40, 20))