import utils import numpy as np from copy import deepcopy lines_raw = utils.read_lines_str_stripped("AOC2021/aoc12/input.txt") def is_big_cave(node): return node[0].isupper() def is_small_cave(node): return node[0].islower() class Graph: def __init__(self): self._edges = {} self._visited = {} self._paths = [] def add_edge(self, node1, node2): if node1 not in self._edges: self._edges[node1] = [] if node2 not in self._edges: self._edges[node2] = [] self._edges[node1].append(node2) self._edges[node2].append(node1) def visit(self, node, c_path, visited): if node == "end":
from utils import read_lines_str_stripped import numpy as np lines = read_lines_str_stripped("AOC2021/aoc03/input.txt") def part_I(bits): num_bits = len(bits[0]) counter = {idx: {i: 0 for i in range(num_bits)} for idx in range(2)} for l in bits: for idx, c in enumerate(l): counter[int(c)][idx] += 1 # gamma rate and the epsilon rate gamma_rate = [ "1" if counter[1][i] > counter[0][i] else "0" for i in range(num_bits) ] gamma_rate = int("".join(gamma_rate), 2) epsilon_rate = [ "0" if counter[1][i] > counter[0][i] else "1" for i in range(num_bits) ] print(num_bits, epsilon_rate) epsilon_rate = int("".join(epsilon_rate), 2) print(gamma_rate * epsilon_rate) def part_II(bits): num_bits = len(bits[0]) def count_bits(num_list, id_bit): counter = {idr: [] for idr in ["0", "1"]}
import utils import numpy as np from copy import deepcopy import mayavi.mlab as mlab lines_raw = utils.read_lines_str_stripped("AOC2021/aoc19/test_input_2.txt") scanners = {} current_scanner = -1 for line in lines_raw: if line.startswith("--- scanner"): current_scanner += 1 scanners[current_scanner] = [] elif line: posX, posY, posZ = [int(a) for a in line.split(",")] scanners[current_scanner].append([posX, posY, posZ]) scanners = { scanner_id: np.array(scanners[scanner_id]) for scanner_id in scanners } print(scanners[0]) def compute_dst(id): return np.array([np.sqrt(np.sum(beacone**2)) for beacone in scanners[id]]) def rotate_x(pts, dir): return np.array([pts[:, 0], pts[:, 2], dir * pts[:, 1]])
from utils import read_lines_str_stripped import numpy as np import uuid class Board: pass lines_raw = read_lines_str_stripped("AOC2021/aoc04/input.txt") draw_nums = [int(a) for a in lines_raw[0].split(",")] class Board: def __init__(self, lines): self._id = uuid.uuid1() self.load_numbers(lines) def load_numbers(self, lines): self._mask = np.zeros((5, 5)).astype(np.int32) self._board = { int(a): (col, row) for row, line in enumerate(lines) for col, a in enumerate(line.split()) } def check(self, num): if num in self._board: col, row = self._board[num] del self._board[num] self._mask[col, row] = 1