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
| 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) |
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
| 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) |
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
| from copy import deepcopy | |
| class Node: | |
| def __init__(self): | |
| self.left = None | |
| self.right = None | |
| self.top = None | |
| def magnitude(self): | |
| m_left = 0 |
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
| 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: |
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
| 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: |
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
| 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 |
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
| 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 |
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
| 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() |
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 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 |
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 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 |
NewerOlder