+/foobar

google programming puzzles

git clone https://git.julia.blue/+/foobar

Joseph RyanI made it2e1d345

master
502 B25 linesraw
1table = {}
2
3
4def solve(prev, n):
5    current = prev, n
6    if current in table:
7        return table[current]
8    if prev == 1:
9        table[current] = 0
10        return 0
11    table[current] = int(n < prev)
12    for i in range(min(prev - 1, n - 1), 0, -1):
13        table[current] += solve(i, n - i)
14    return table[current]
15
16
17def answer(n):
18    return solve(n, n)
19
20
21for i in range(200):
22    print answer(i)
23
24# f = open("grid.csv", 'w')
25# f.write('\n'.join([', '.join(map(str, row)) for row in table]))