Esempio n. 1
0
from tools.euler import polygonal

# collect all polygonals in range
fourdigits = []
beginnings, endings = set(), set()
for i in [3, 4, 5, 6, 7, 8]:
    row = []
    n = 1
    p = polygonal(i, n)
    while p < 10000:
        n += 1
        p = polygonal(i, n)
        if p < 1000:
            continue
        row.append(p)
        beginnings.add(p // 100)
        endings.add(p % 100)
    fourdigits.append(row)

# make sure every polygonal can be part of a chain
commons = beginnings & endings
for i in range(6):
    newfourdigits = []
    for fd in fourdigits[i]:
        if fd % 100 in commons and fd // 100 in commons:
            newfourdigits.append(fd)
    fourdigits[i] = newfourdigits


# recursively look for chain
def find_chain(rows, terms):
Esempio n. 2
0
from operator import mul
from functools import reduce

from tools.euler import polygonal

total = 0
for n in range(2, 16):
    step = (1.0 * n) / polygonal(3, n)
    total += int(reduce(mul, [(step * i) ** i for i in range(1, n + 1)], 1.0))
print(total)
Esempio n. 3
0
from tools.euler import polygonal, sigma

t = 1
while sigma(0, polygonal(3, t)) < 500:
    t += 1
polygon = polygonal(3, t)
print(polygon)
Esempio n. 4
0
def get_term(i):
    if i & 1 == 1:
        p = (i + 1) // 2
    else:
        p = -(i // 2)
    return polygonal(5, p)
Esempio n. 5
0
def is_triangle_word(w):
    t = sum([ascii_uppercase.index(c) + 1 for c in w])
    n = int((2 * t) ** 0.5)
    return polygonal(3, n) == t
Esempio n. 6
0
from tools.euler import polygonal

tN, pN, hN = 285, 165, 143
t, p, h = polygonal(3, tN), polygonal(5, pN), polygonal(6, hN)
while True:
    hN += 1
    h = polygonal(6, hN)
    while p < h:
        pN += 1
        p = polygonal(5, pN)
    while t < p:
        tN += 1
        t = polygonal(3, tN)
    if h == p == t:
        break
print(t)
Esempio n. 7
0
from tools.euler import polygonal

TARGET = 2 * 10**6
closest, closest_rows, closest_cols = 0, 0, 0
for rows in range(1, 100):
    for cols in range(rows + 1, 100):
        rectangles = polygonal(3, rows) * polygonal(3, cols)
        if abs(TARGET - closest) > abs(TARGET - rectangles):
            closest, closest_rows, closest_cols = rectangles, rows, cols

args = (closest, closest_rows, closest_cols)
message = "closest=%d rows=%d cols=%d" % args
print(message)
message = "rows*cols=%d" % (closest_rows * closest_cols)
print(message)
Esempio n. 8
0
import sys

from tools.euler import polygonal

SIZE = 2500
pentas = [polygonal(5, i) for i in range(1, SIZE + 1)]

for a in range(len(pentas)):
    for b in range(a + 1, len(pentas)):
        if pentas[b] + pentas[a] in pentas and pentas[b] - pentas[a] in pentas:
            difference = pentas[b] - pentas[a]
            print(difference)
            sys.exit(0)