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 === | |
obstacles = set() | |
walls = set() | |
initial_position = None | |
with open("input.txt", "r") as f: | |
for y, line in enumerate(iter(f.readline, "\n")): | |
for x, char in enumerate(line.strip()): | |
if char == "@": | |
initial_position = (x, y) |
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 === | |
import re | |
LINE_RE = re.compile(r"p=(\d+),(\d+) v=(-?\d+),(-?\d+)") | |
WIDTH = 101 | |
HEIGHT = 103 | |
robots = [] | |
with open("input.txt", "r") as f: | |
for line in f: |
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 fractions import Fraction as F | |
from itertools import batched | |
import re | |
BUTTON_RE = re.compile(r"Button .: X\+(\d+), Y\+(\d+)") | |
PRIZE_RE = re.compile(r"Prize: X=(\d+), Y=(\d+)") | |
games = [] | |
with open("input.txt", "r") as f: |
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 | |
garden = defaultdict(str) | |
with open("input.txt", "r") as f: | |
for y, line in enumerate(f): | |
for x, plot in enumerate(line.strip()): | |
garden[x, y] = plot | |
WIDTH = x + 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 === | |
with open("input.txt", "r") as f: | |
nums = map(int, f.read().split()) | |
# === Part 1 === | |
from collections import Counter | |
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 | |
map = defaultdict(lambda: -1) | |
with open("input.txt", "r") as f: | |
for y, line in enumerate(f): | |
for x, char in enumerate(line.strip()): | |
map[x, y] = int(char) | |
MAX_X = x | |
MAX_Y = y |
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: | |
filesystem_string = f.read().strip() | |
filesystem = [ | |
[(idx // 2 if idx % 2 == 0 else None, int(char))] | |
for idx, char in enumerate(filesystem_string) | |
] |
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 === | |
antennas = {} | |
with open("input.txt", "r") as f: | |
for y, line in enumerate(f): | |
for x, char in enumerate(line.strip()): | |
if char != ".": | |
antennas.setdefault(char, set()).add((x, y)) | |
max_x = x |
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 === | |
equations = [] | |
with open("input.txt", "r") as f: | |
for line in f: | |
target, _, operands = line.partition(":") | |
equations.append( | |
( | |
int(target), | |
[int(num) for num in operands.split()], |
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 === | |
obstacles = set() # (x, y) positions of the obstacles. | |
initial_position = None | |
with open("input.txt", "r") as f: | |
for y, line in enumerate(f): | |
for x, char in enumerate(line): | |
if char == "#": | |
obstacles.add((x, y)) | |
elif char == "^": |