Skip to content

Instantly share code, notes, and snippets.

elves = []
current_elf = 0
with open('input.txt', encoding="utf-8") as file:
for line in file.readlines():
line = line.strip()
if line == '':
elves.append(current_elf)
current_elf = 0
continue
current_elf += int(line)
elves = []
current_elf = 0
with open('input.txt', encoding="utf-8") as file:
for line in file.readlines():
line = line.strip()
if line == '':
elves.append(current_elf)
current_elf = 0
continue
current_elf += int(line)
from copy import deepcopy
class Node:
def __init__(self):
self.left = None
self.right = None
self.top = None
def magnitude(self):
m_left = 0
class Node:
def __init__(self):
self.left = None
self.right = None
self.top = None
def magnitude(self):
m_left = 0
m_right = 0
if type(self.left) == int:
def simulate(dx, dy, x1, x2, y1, y2):
x, y = (0, 0)
initial_dx, initial_dy = dx, dy
while True:
x += dx
y += dy
dy -= 1
if dx < 0:
dx += 1
elif dx > 0:
def simulate(dx, dy, x1, x2, y1, y2):
x, y = (0, 0)
hit = False
max_y = -999999
while True:
x += dx
y += dy
dy -= 1
if dx < 0:
dx += 1
TAG_LITERAL = 4
TAG_SUM = 0
TAG_PRODUCT = 1
TAG_MIN = 2
TAG_MAX = 3
TAG_GT = 5
TAG_LT = 6
TAG_EQ = 7
TYPE_BITS = 0
TAG_LITERAL = 4
TYPE_BITS = 0
class Stream:
def __init__(self, data):
self.data = data
self.ready_carry = 0
self.carry_size = 0
self.carry = 0
self.nibbles = self._init_read()
import heapq
def get(x, y, cave):
overflow = y // len(cave)
y = y % len(cave)
overflow += x // len(cave[y])
x = x % len(cave[y])
value = cave[y][x]
value += overflow
value %= 9
import heapq
def adjacent(x, y, cave):
deltas = [(-1, 0), (0, -1), (1, 0), (0, 1)]
for delta_x, delta_y in deltas:
candidate_x = x + delta_x
candidate_y = y + delta_y
if (candidate_y >= 0 and candidate_y < len(cave) and
candidate_x >= 0 and candidate_x < len(cave[candidate_y])):
yield candidate_x, candidate_y