Skip to content

Instantly share code, notes, and snippets.

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)]
('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
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,
@expectancyViolation
expectancyViolation / solve.py
Created March 13, 2024 17:46
solve wooden cube
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]