In [16]:
#!/usr/bin/python
import itertools
In [17]:
flatten_iter = itertools.chain.from_iterable
def factors(n):
return set(flatten_iter((i, n//i)
for i in range(1, int(n**0.5)+1) if n % i == 0))
In [ ]:
goal = 34000000
found = False
housenumber = 0
while not found:
housenumber += 1
if housenumber % 10000 == 0:
print ("Checking house: %d" % (housenumber))
visiting_elfs = list(factors(housenumber))
non_lazy_visiting_elfs = []
for elf_id in visiting_elfs:
if (elf_id > housenumber/50):
non_lazy_visiting_elfs.append(elf_id)
presents = sum(non_lazy_visiting_elfs)*11
if (presents) > goal:
print ("house", housenumber)
found = True
In [24]:
print ("house", housenumber)
In [ ]: