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.

Add chunks method to utils.py

+9 -3
+9 -3
2016/utils.py
··· 10 10 11 11 def mul(lst): 12 12 """Like sum(), but for multiplication.""" 13 - return reduce(operator.mul, lst, 1) 13 + return reduce(operator.mul, lst, 1) # NOQA 14 + 15 + 16 + def chunks(l, n): 17 + """Yield successive n-sized chunks from l.""" 18 + for i in range(0, len(l), n): 19 + yield l[i:i + n] 14 20 15 21 16 22 def factors(n): 17 23 """Returns the factors of n.""" 18 24 return sorted( 19 25 x for tup in ( 20 - [i, n//i] for i in range(1, int(n**0.5) + 1) 26 + [i, n // i] for i in range(1, int(n ** 0.5) + 1) 21 27 if n % i == 0) 22 28 for x in tup) 23 29 ··· 48 54 yield i 49 55 50 56 # Mark factors as non-prime 51 - for n in xrange(i * i, n, i): 57 + for n in xrange(i * i, n, i): # NOQA 52 58 _primes[n] = False 53 59 54 60