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 matrix transpose and rotation functions

+14 -2
+4 -2
2017/starter.py
··· 6 6 from collections import Counter, defaultdict, deque, namedtuple # NOQA 7 7 from itertools import count, product, permutations, combinations, combinations_with_replacement # NOQA 8 8 9 - from utils import (parse_line, mul, all_unique, factors, memoize, primes, new_table, md5, sha256, knot_hash, # NOQA 10 - Point, DIRS, DIRS_4, DIRS_8) # NOQA 9 + from utils import parse_line, mul, all_unique, factors, memoize, primes # NOQA 10 + from utils import new_table, transposed, rotated # NOQA 11 + from utils import md5, sha256, knot_hash # NOQA 12 + from utils import Point, DIRS, DIRS_4, DIRS_8 # NOQA 11 13 12 14 # Itertools Functions: 13 15 # product('ABCD', repeat=2) AA AB AC AD BA BB BC BD CA CB CC CD DA DB DC DD
+10
2017/utils.py
··· 25 25 return [[val for _ in range(width)] for _ in range(height)] 26 26 27 27 28 + def transposed(matrix): 29 + """Returns the transpose of the given matrix.""" 30 + return [list(r) for r in zip(*matrix)] 31 + 32 + 33 + def rotated(matrix): 34 + """Returns the given matrix rotated 90 degrees clockwise.""" 35 + return [list(r) for r in zip(*matrix[::-1])] 36 + 37 + 28 38 def mul(lst): 29 39 """Like sum(), but for multiplication.""" 30 40 return reduce(operator.mul, lst, 1) # NOQA