Day 20 - Advent of Code 2015
Working solutions for the day 20 puzzles.
Part One
""" day_20_01.py """
# usage: python3 day_20_01.py < input
import math
def sum_factors(dividend):
""" sum factors of dividend """
factors = set()
limit = int(math.sqrt(dividend))
for i in range(1, limit + 1):
quotient, remainder = divmod(dividend, i)
if remainder == 0:
factors.add(i)
factors.add(quotient)
return sum(factors)
presents = int(input())
house = 1
while sum_factors(house) * 10 < presents:
house += 1
print(house)
Part Two
""" day_20_02.py """
# usage: python3 day_20_02.py < input
import math
def sum_limited_factors(dividend):
""" sum limited factors of dividend """
factors = set()
limit = int(math.sqrt(dividend))
for i in range(1, limit + 1):
quotient, remainder = divmod(dividend, i)
if remainder == 0:
if quotient <= 50:
factors.add(i)
if i <= 50:
factors.add(quotient)
return sum(factors)
presents = int(input())
house = 1
while sum_limited_factors(house) * 11 < presents:
house += 1
print(house)