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 sys | |
import re | |
data = sys.stdin.read() | |
PARAMS = list( | |
zip( | |
map(int, re.findall("div z (26|1)", data)), | |
map(int, re.findall("add x (-?[0-9]+)", data)), | |
map(int, re.findall("add y w\nadd y (-?[0-9]+)", data, re.M)), |
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 functools | |
import sys | |
AMPHIPODS = "".join(c for c in sys.stdin.read() if c in "ABCD\n").strip().split("\n") | |
AMPHIPODS = [AMPHIPODS, [AMPHIPODS[0], "DCBA", "DBAC", AMPHIPODS[1]]] | |
PARTS = [ | |
tuple([tuple(["."] * 11)] + [tuple(row[i] for row in amphipods) for i in range(4)]) | |
for amphipods in AMPHIPODS | |
] |
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 itertools | |
import functools | |
import sys | |
AXIS_ORIENTATIONS = list(itertools.product([-1, 1], [-1, 1], [-1, 1])) | |
AXIS_ORDERS = list(itertools.permutations(range(3), 3)) | |
def shift_scanner(scanner, vector): | |
return tuple(tuple(c + d for c, d in zip(point, vector)) for point in scanner) |
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 | |
import sys | |
# 3d regions represented as tuples of 3 tuples: ((x1, x2), (y1, y2), (z1, z2)) | |
def valid(r): | |
return all(c[0] <= c[1] for c in r) |
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 collections | |
import functools | |
import itertools | |
POSITIONS = (9, 6) | |
DICE = [1, 2, 3] | |
SUMS = collections.defaultdict(int) | |
for a, b, c in itertools.product(DICE, DICE, DICE): | |
SUMS[a + b + c] += 1 |
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 | |
import sys | |
from collections import defaultdict | |
def parse_data(): | |
pairs = defaultdict(int) | |
data = sys.stdin | |
polymer = data.readline().strip() | |
rules = {} |
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
#!/usr/bin/env python3 | |
import sys | |
import re | |
points = set() | |
folds = [] | |
for line in sys.stdin: | |
line = line.strip() |
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 sys | |
EDGES = {tuple(line.strip().split("-")) for line in sys.stdin if line.strip()} | |
VERTICES = set(e[0] for e in EDGES) | set(e[1] for e in EDGES) | |
MAP = { | |
v: set( | |
w for w in VERTICES if (((v, w) in EDGES) or ((w, v) in EDGES)) and w != "start" | |
) | |
for v in VERTICES | |
} |
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
#!/usr/bin/env python3 | |
import collections | |
import dataclasses | |
import re | |
import sys | |
PART = 2 | |
PATTERN = re.compile("([0-9]+),([0-9]+) -> ([0-9]+),([0-9]+)") |