adventOfCode/17-conwayCubes/python/common.py
Tom aed18d1ac8
Day 17 (Python)
Third time lucky!
... it was not worth staying up until 1am for this
2020-12-18 00:53:41 +00:00

23 lines
No EOL
649 B
Python

from typing import Dict, Tuple, Callable
import itertools
active_marker = "#"
inactive_marker = "."
translation_vectors_3d = [p for p in itertools.product([-1, 0, 1], repeat=3) if p != (0, 0, 0)]
translation_vectors_4d = [p for p in itertools.product([-1, 0, 1], repeat=4) if p != (0, 0, 0, 0)]
def parse(instr: str, key:Callable[[int, int], int]) -> Dict[Tuple[int, int, int], str]:
input_lists = [[x for x in y] for y in instr.strip().split("\n")]
rtvl = {}
for y, row in enumerate(input_lists):
for x, col in enumerate(row):
if col != inactive_marker:
rtvl[key(x, y)] = col
return rtvl