Skip to content

Instantly share code, notes, and snippets.

@cnorthwood
Last active December 20, 2015 14:51
Show Gist options
  • Save cnorthwood/1e562b3793c2284173cf to your computer and use it in GitHub Desktop.
Save cnorthwood/1e562b3793c2284173cf to your computer and use it in GitHub Desktop.
AoC day 20
from __future__ import print_function
from itertools import chain, count
from math import sqrt
TARGET = 36000000
factors = lambda i: set(chain.from_iterable((x, i // x) for x in filter(lambda x: i % x == 0, range(1, int(sqrt(i)) + 1))))
part_one = False
part_two = False
for i in count(start=1):
f = factors(i)
if not part_one and sum(f) * 10 >= TARGET:
print("Part One:", i)
part_one = True
if not part_two and sum(filter(lambda x: x * 50 >= i, f)) * 11 >= TARGET:
print("Part Two:", i)
part_two = True
if part_one and part_two:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment