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
# === Parsing === | |
keys = [] | |
locks = [] | |
with open("input.txt", "r") as f: | |
contents = f.read() | |
for block in contents.split("\n\n"): | |
lines = block.splitlines() | |
counts = [col.count("#") - 1 for col in zip(*lines)] |
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
# === Parsing === | |
values = {} | |
dependencies = {} | |
zs = set() | |
with open("input.txt", "r") as f: | |
for line in iter(f.readline, "\n"): | |
wire, value = line.strip().split(": ") | |
values[wire] = int(value) |
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
# === Parsing === | |
from collections import defaultdict | |
edges = defaultdict(set) | |
with open("input.txt", "r") as f: | |
for line in f: | |
n1, n2 = line.strip().split("-") | |
edges[n1].add(n2) | |
edges[n2].add(n1) |
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
# === Parsing === | |
with open("input.txt", "r") as f: | |
seeds = [int(line) for line in f] | |
# === Part 1 === | |
from collections import deque | |
from itertools import islice |
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
# === Parsing === | |
with open("input.txt", "r") as f: | |
codes = [line.strip() for line in f] | |
print(codes) | |
# === Part 1 === | |
numpad_pos = { |
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
# === Parsing === | |
valid = set() | |
start = None | |
end = None | |
with open("input.txt", "r") as f: | |
for y, line in enumerate(f): | |
for x, char in enumerate(line.strip()): | |
if char in ".SE": |
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
# === Parsing === | |
with open("input.txt", "r") as f: | |
towels = tuple(f.readline().strip().split(", ")) | |
_ = f.readline() | |
patterns = [line.strip() for line in f] | |
# === Part 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
# === Parsing === | |
from itertools import product | |
SIZE = 70 | |
with open("input.txt", "r") as f: | |
falling_bytes = [tuple(int(num) for num in line.split(",")) for line in f] | |
valid = set(product(range(SIZE + 1), repeat=2)) |
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
# === Parsing === | |
with open("input.txt", "r") as f: | |
register_a = int(f.readline().split()[-1]) | |
register_b = int(f.readline().split()[-1]) | |
register_c = int(f.readline().split()[-1]) | |
_ = f.readline() | |
program = [int(num) for num in f.readline().split()[-1].split(",")] | |
print(program, register_a, register_b, register_c) |
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
# === Parsing === | |
start = None | |
end = None | |
valid = set() | |
with open("input.txt", "r") as f: | |
for y, line in enumerate(f): | |
for x, char in enumerate(line.strip()): | |
if char in ".SE": | |
valid.add((x, y)) |
NewerOlder