This file contains 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 | |
line_format = re.compile(r'(on|off) x=(-?\d+)..(-?\d+),y=(-?\d+)..(-?\d+),z=(-?\d+)..(-?\d+)') | |
def read_line(line): | |
instr, *bounds = line_format.search(line).groups() | |
return instr, tuple(int(bound) for bound in bounds) |
This file contains 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
def play(player_a_start, player_b_start): | |
a_score = 0 | |
b_score = 0 | |
a_pos = player_a_start | |
b_pos = player_b_start | |
die_rolls = 0 | |
next_die_value = 0 | |
def dice(): |
This file contains 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
def read_file(file): | |
i = iter(line.strip() for line in file) | |
algo = [c == '#' for c in next(i)] | |
assert len(algo) == 512 | |
assert next(i) == '' | |
grid = set((x, y) for y, line in enumerate(i) for x, c in enumerate(line) if c == '#') | |
return algo, grid |
This file contains 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
def read_file(file): | |
stripped = (line.strip() for line in file) | |
scanners = [] | |
for line in stripped: | |
if line.startswith('---'): | |
scanner = set() | |
scanners.append(scanner) | |
elif len(line) > 0: | |
x_str, y_str, z_str = line.split(',') |
This file contains 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 math | |
def value_at(smallfish_number, path): | |
cursor = smallfish_number | |
for e in path: | |
if e == 'L': | |
cursor = cursor[0] | |
else: |
This file contains 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 functools import reduce | |
LITERAL = 4 | |
TOTAL_LENGTH = 0 | |
def hex_convert(c): | |
d = int(c, 16) | |
b = 8 |
This file contains 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 | |
def read_file(file): | |
i = iter(file) | |
start_string = next(i).strip() | |
next(i) | |
inserts = dict() |
This file contains 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 | |
def read_line(line): | |
if m := re.match(r'(\d+),(\d+)', line): | |
x_str, y_str = m.groups() | |
return (int(x_str), int(y_str)), None | |
elif m := re.match(r'fold along ([xy])=(\d+)', line): | |
axis, pos = m.groups() | |
return None, (axis, int(pos)) |
This file contains 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
def cave_system(lines): | |
edges = {} | |
for line in lines: | |
start_label, end_label = line.strip().split("-") | |
targets = edges.get(start_label, set()) | |
targets.add(end_label) | |
edges[start_label] = targets | |
reverse_targets = edges.get(end_label, set()) |
This file contains 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
class Octopus(object): | |
def __init__(self, initial_energy): | |
self.energy = initial_energy | |
self.adjacent_octopi = [] | |
self.has_flashed = False | |
def add_adjacent(self, octopus): | |
self.adjacent_octopi.append(octopus) |
NewerOlder