Пример #1
0
def solution():
    count = 0
    for n in xrange(1, 101):
        for r in xrange(0, n):
            c = combination(n, r)
            if c > 1000000:
                count += n-2*r+1
                break
    return count
Пример #2
0
#! /usr/bin/env python

from util import combination

if __name__ == "__main__":
    print combination(40, 20)
Пример #3
0
def rectangles(a, b):
    return combination(a + 1, 2) * combination(b + 1, 2)
Пример #4
0
from util import combination

def rectangles(a, b):
    return combination(a + 1, 2) * combination(b + 1, 2)

best_xy, best_rects = 0, 0
for x in xrange(1, 2000):
    for y in xrange(1, 2000):
        rects = combination(x + 1, 2) * combination(y + 1, 2)
        if abs(rects - 2000000) < abs(best_rects - 2000000):
            best_rects = rects
            best_xy = x*y
        if rects > 2000000:
            break

print best_xy
Пример #5
0
# Lattice paths
# Problem 15
#
# Starting in the top left corner of a 2x2 grid, and only being able to move to
# the right and down, there are exactly 6 routes to the bottom right corner.
#
#   xxxxx  xxx-+  xxx-+  x-+-+  x-+-+  x-+-+
#   | | x  | x |  | x |  x | |  x | |  x | |
#   +-+-x  +-xxx  +-x-+  xxxxx  xxx-+  x-+-+
#   | | x  | | x  | x |  | | x  | x |  x | |
#   +-+-x  +-+-x  +-xxx  +-+-x  +-xxx  xxxxx
#
# How many such routes are there through a 20x20 grid?
#
# Answer: 137846528820

from util import combination

M = 20
N = 20

print combination(M + N, M)
Пример #6
0
from util import combination

ans = 0

for n in xrange(23, 100+1):
    for r in xrange(n+1):
        if combination(n, r) > 1000000:
            ans += 1

print ans