Problem 225

completed January 28, 2021

Comments

This solution is garbage. It takes 23 minutes to run. It’s just a brute force solution. I’m sure there’s some way to figure out what the divisors of the series are, but I never got there.

Code

def t(n):
    yield 1
    yield 1
    yield 1
    t1 = t2 = t3 = 1
    for _ in range(n-3):
        t1, t2, t3 = t2, t3, t1+t2+t3
        yield t3

def solve(n):
    tribs = tuple(t(10**5))
    count = 0
    k = 1
    while count < n:
        k += 2
        for tr in tribs:
            if tr % k == 0:
                break
        else:
            count += 1
    return k

if __name__ == '__main__':
    import sys
    n = eval(sys.argv[1])
    print(solve(n))

Tests

import pytest
from problem import solve, t

_test_t = (
        (10, (1, 1, 1, 3, 5, 9, 17, 31, 57, 105)),
)

@pytest.mark.parametrize('n,expect', _test_t)
def test_t(n, expect):
    assert expect == tuple(t(n))

_test_solve = (
        (1, 27),
        (2, 81),
        (3, 91),
        (4, 103),
        (5, 135),
        (6, 163),
        (7, 189),
        (8, 199),
        (9, 203),
        (10, 221),
)

@pytest.mark.parametrize('n,expect', _test_solve)
def test_solve(n, expect):
    assert expect == solve(n)