what.
This commit is contained in:
parent
deb74bc8f9
commit
efd1fa7e57
21
2018/12.py
21
2018/12.py
@ -57,6 +57,23 @@ with open('data/12.txt') as f:
|
||||
pots = grow(initial, 20)
|
||||
print(f'Part 1: {sum(pots)}\n')
|
||||
|
||||
pots = grow(initial, 5 * 10 ** 10, True)
|
||||
print(f'Part 2: {pots}\n')
|
||||
|
||||
# find pattern and exploit
|
||||
first_stable = 0
|
||||
prev_gen = []
|
||||
for i in range(1, 1000):
|
||||
current_gen = sorted(grow(initial, i))
|
||||
if current_gen == [x + 1 for x in prev_gen]:
|
||||
first_stable = i - 1
|
||||
break
|
||||
else:
|
||||
prev_gen = current_gen
|
||||
magic_number = sum(prev_gen)
|
||||
|
||||
|
||||
def cheat(num_gens):
|
||||
if num_gens < first_stable:
|
||||
raise RuntimeError("Can't cheat.")
|
||||
return magic_number + (num_gens - first_stable) * len(prev_gen)
|
||||
|
||||
print(f'Part 2: {cheat(5 * 10 ** 10)}\n')
|
||||
|
Loading…
x
Reference in New Issue
Block a user