My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 30 lines 532 B view raw
1import fileinput 2 3PRESENTS = int(fileinput.input()[0].strip()) 4CACHE = {} 5 6 7def factors(n): 8 if n in CACHE: 9 return CACHE[n] 10 11 CACHE[n] = set() 12 13 for i in range(1, int(n**0.5) + 1): 14 if n % i == 0: 15 CACHE[n] |= set([i, n//i]) 16 17 return CACHE[n] 18 19 20house = 1 21while sum(factors(house)) * 10 < PRESENTS: 22 house += 1 23 24print "Lowest house number #1:", house 25 26house = 1 27while sum(x for x in factors(house) if (x * 50 >= house)) * 11 < PRESENTS: 28 house += 1 29 30print "Lowest house number #2:", house