This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| from collections import defaultdict | |
| from itertools import product | |
| import numpy as np | |
| def mat_prod(arr1, arr2): | |
| L = len(arr1) | |
| res = [[sum(arr1[i][k] * arr2[k][j] for k in range(L)) for j in range(L)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ('A', 'v') replace with <vA | |
| ('v', '<') replace with <A | |
| ('<', '<') replace with A | |
| ('<', 'A') replace with >>^A | |
| ('A', '<') replace with v<<A | |
| ('<', 'v') replace with >A | |
| ('A', '>') replace with vA | |
| ('>', '>') replace with A | |
| ('>', '^') replace with <^A | |
| ('^', 'A') replace with >A |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import deque | |
| with open("input.txt", "r") as bb: | |
| coords = [tuple([int(x) for x in line.strip().split(",")]) for line in bb] | |
| # old solution did not work reliably. this one should | |
| # dijkstra exploring paths in order of their "earliest closure" i.e. the time at which they get blocked | |
| def part2(coords: list[tuple[int, int]]): | |
| latenesses = defaultdict(lambda: -inf, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from dataclasses import dataclass | |
| from itertools import product | |
| from typing import Tuple, Dict | |
| # directions are elements of {-1,0,1}^3 s.t. exactly 1 element is nonzero | |
| def get_dir(i, s): | |
| res = [0, 0, 0] |