year
stringdate
2024-01-01 00:00:00
2024-01-01 00:00:00
day
stringclasses
25 values
part
stringclasses
2 values
question
stringclasses
50 values
answer
stringclasses
49 values
solution
stringlengths
143
12.8k
language
stringclasses
3 values
2024
2
1
--- Day 2: Red-Nosed Reports --- Fortunately, the first location The Historians want to search isn't a long walk from the Chief Historian's office. While the Red-Nosed Reindeer nuclear fusion/fission plant appears to contain no sign of the Chief Historian, the engineers there run up to you as soon as they see you. Ap...
341
def parseInput(): input = [] with open('input.txt', 'r') as file: tmp = file.read().splitlines() tmp2 = [i.split(' ') for i in tmp] for item in tmp2: input.append([int(i) for i in item]) return input if __name__ == "__main__": input = parseInput() ...
python
2024
2
1
--- Day 2: Red-Nosed Reports --- Fortunately, the first location The Historians want to search isn't a long walk from the Chief Historian's office. While the Red-Nosed Reindeer nuclear fusion/fission plant appears to contain no sign of the Chief Historian, the engineers there run up to you as soon as they see you. Ap...
341
import sys input_path = sys.argv[1] if len(sys.argv) > 1 else "input.txt" def solve(input): with open(input) as f: lines = f.read().splitlines() L = [list(map(int, line.split(" "))) for line in lines] # L = [[int(l) for l in line.split(" ")] for line in lines] counter = 0 for l in L: ...
python
2024
2
1
--- Day 2: Red-Nosed Reports --- Fortunately, the first location The Historians want to search isn't a long walk from the Chief Historian's office. While the Red-Nosed Reindeer nuclear fusion/fission plant appears to contain no sign of the Chief Historian, the engineers there run up to you as soon as they see you. Ap...
341
l = [list(map(int,x.split())) for x in open("i.txt")] print(sum(any(all(d<b-a<u for a,b in zip(s,s[1:])) for d,u in[(0,4),(-4,0)])for s in l))
python
2024
2
1
--- Day 2: Red-Nosed Reports --- Fortunately, the first location The Historians want to search isn't a long walk from the Chief Historian's office. While the Red-Nosed Reindeer nuclear fusion/fission plant appears to contain no sign of the Chief Historian, the engineers there run up to you as soon as they see you. Ap...
341
import sys input_path = sys.argv[1] if len(sys.argv) > 1 else "input.txt" def solve(input): with open(input) as f: lines = f.read().splitlines() L = [list(map(int, line.split(" "))) for line in lines] counter = 0 for l in L: inc_dec = l == sorted(l) or l == sorted(l, reverse=True) ...
python
2024
2
1
--- Day 2: Red-Nosed Reports --- Fortunately, the first location The Historians want to search isn't a long walk from the Chief Historian's office. While the Red-Nosed Reindeer nuclear fusion/fission plant appears to contain no sign of the Chief Historian, the engineers there run up to you as soon as they see you. Ap...
341
with open('input.txt', 'r') as file: lines = file.readlines() sum = 0 for line in lines: A = [int(x) for x in line.split()] ascending = False valid = True if A[0] < A[1]: ascending = True for i in range(len(A) - 1): if ascending: ...
python
2024
2
2
--- Day 2: Red-Nosed Reports --- Fortunately, the first location The Historians want to search isn't a long walk from the Chief Historian's office. While the Red-Nosed Reindeer nuclear fusion/fission plant appears to contain no sign of the Chief Historian, the engineers there run up to you as soon as they see you. Ap...
404
def is_safe(levels: list[int]) -> bool: # Calculate the difference between each report differences = [first - second for first, second in zip(levels, levels[1:])] max_difference = 3 return (all(0 < difference <= max_difference for difference in differences) or all(-max_difference <= differe...
python
2024
2
2
--- Day 2: Red-Nosed Reports --- Fortunately, the first location The Historians want to search isn't a long walk from the Chief Historian's office. While the Red-Nosed Reindeer nuclear fusion/fission plant appears to contain no sign of the Chief Historian, the engineers there run up to you as soon as they see you. Ap...
404
def if_asc(x): result = all(y < z for y,z in zip(x, x[1:])) return result def if_dsc(x): result = all (y > z for y,z in zip(x, x[1:])) return result def if_asc_morethan3(x): result = all(y > z - 4 for y,z in zip(x,x[1:])) return result def if_dsc_morethan3(x): result = all(y < z + 4 for y...
python
2024
2
2
--- Day 2: Red-Nosed Reports --- Fortunately, the first location The Historians want to search isn't a long walk from the Chief Historian's office. While the Red-Nosed Reindeer nuclear fusion/fission plant appears to contain no sign of the Chief Historian, the engineers there run up to you as soon as they see you. Ap...
404
import sys import logging # logging.basicConfig(,level=sys.argv[2]) input_path = sys.argv[1] if len(sys.argv) > 1 else "input.txt" def is_ok(lst): inc_dec = lst == sorted(lst) or lst == sorted(lst, reverse=True) size_ok = True for i in range(len(lst) - 1): if not 0 < abs(lst[i] - lst[i + 1]) <= ...
python
2024
2
2
--- Day 2: Red-Nosed Reports --- Fortunately, the first location The Historians want to search isn't a long walk from the Chief Historian's office. While the Red-Nosed Reindeer nuclear fusion/fission plant appears to contain no sign of the Chief Historian, the engineers there run up to you as soon as they see you. Ap...
404
count = 0 def safe(levels): # Check if the sequence is either all increasing or all decreasing if all(levels[i] < levels[i + 1] for i in range(len(levels) - 1)): # Increasing diffs = [levels[i + 1] - levels[i] for i in range(len(levels) - 1)] elif all(levels[i] > levels[i + 1] for i in range(len(l...
python
2024
2
2
--- Day 2: Red-Nosed Reports --- Fortunately, the first location The Historians want to search isn't a long walk from the Chief Historian's office. While the Red-Nosed Reindeer nuclear fusion/fission plant appears to contain no sign of the Chief Historian, the engineers there run up to you as soon as they see you. Ap...
404
def check_sequence(numbers): nums = [int(x) for x in numbers.split()] # First check if sequence is valid as is if is_valid_sequence(nums): return True # Try removing one number at a time for i in range(len(nums)): test_nums = nums[:i] + nums[i+1:] if is_valid_se...
python
2024
1
1
--- Day 1: Historian Hysteria --- The Chief Historian is always present for the big Christmas sleigh launch, but nobody has seen him in months! Last anyone heard, he was visiting locations that are historically significant to the North Pole; a group of Senior Historians has asked you to accompany them as they check th...
2378066
def parseInput(): left = [] right = [] with open('input.txt', 'r') as file: input = file.read().splitlines() for line in input: split = line.split(" ") left.append(int(split[0])) right.append(int(split[1])) return left, right def sort(arr: list): ...
python
2024
1
1
--- Day 1: Historian Hysteria --- The Chief Historian is always present for the big Christmas sleigh launch, but nobody has seen him in months! Last anyone heard, he was visiting locations that are historically significant to the North Pole; a group of Senior Historians has asked you to accompany them as they check th...
2378066
def find_min_diff(a, b): sorted_a = sorted(a) sorted_b = sorted(b) d = 0 for i in range(len(sorted_a)): d += abs(sorted_a[i] - sorted_b[i]) return d def read_input_file(file_name): a = [] b = [] with open(file_name, "r") as file: for line in file: values = l...
python
2024
1
1
--- Day 1: Historian Hysteria --- The Chief Historian is always present for the big Christmas sleigh launch, but nobody has seen him in months! Last anyone heard, he was visiting locations that are historically significant to the North Pole; a group of Senior Historians has asked you to accompany them as they check th...
2378066
input = open("day_01\input.txt", "r") distance = 0 left_list = [] right_list = [] for line in input: values = [x for x in line.strip().split()] left_list += [int(values[0])] right_list += [int(values[1])] left_list.sort() right_list.sort() for i in range(len(left_list)): distance += abs(left_lis...
python
2024
1
1
--- Day 1: Historian Hysteria --- The Chief Historian is always present for the big Christmas sleigh launch, but nobody has seen him in months! Last anyone heard, he was visiting locations that are historically significant to the North Pole; a group of Senior Historians has asked you to accompany them as they check th...
2378066
def read_input(file_path: str) -> list[tuple[int, int]]: """ Reads a file and returns its contents as a list of tuples of integers. Args: file_path (str): The path to the input file. Returns: list of tuple of int: A list where each element is a tuple of integers representing a...
python
2024
1
1
--- Day 1: Historian Hysteria --- The Chief Historian is always present for the big Christmas sleigh launch, but nobody has seen him in months! Last anyone heard, he was visiting locations that are historically significant to the North Pole; a group of Senior Historians has asked you to accompany them as they check th...
2378066
with open("AdventOfCode D-1 input.txt", "r") as file: content = file.read() lines = content.splitlines() liste_1 = [] liste_2 = [] for i in range(len(lines)): mots = lines[i].split() liste_1.append(int(mots[0])) liste_2.append(int(mots[1])) liste_paires = [] index = 0 while liste_1 != []: list...
python
2024
1
2
--- Day 1: Historian Hysteria --- The Chief Historian is always present for the big Christmas sleigh launch, but nobody has seen him in months! Last anyone heard, he was visiting locations that are historically significant to the North Pole; a group of Senior Historians has asked you to accompany them as they check th...
18934359
def calculate_similarity_score(left, right): score = 0 for left_element in left: score += left_element * num_times_in_list(left_element, right) return score def num_times_in_list(number, right_list): num_times = 0 for element in right_list: if number == element: num_time...
python
2024
1
2
--- Day 1: Historian Hysteria --- The Chief Historian is always present for the big Christmas sleigh launch, but nobody has seen him in months! Last anyone heard, he was visiting locations that are historically significant to the North Pole; a group of Senior Historians has asked you to accompany them as they check th...
18934359
leftNums, rightNums = [], [] with open('input.txt') as input: while line := input.readline().strip(): left, right = line.split() leftNums.append(int(left.strip())) rightNums.append(int(right.strip())) total = 0 for i in range(len(leftNums)): total += leftNums[i] * rightNums.count(leftN...
python
2024
1
2
--- Day 1: Historian Hysteria --- The Chief Historian is always present for the big Christmas sleigh launch, but nobody has seen him in months! Last anyone heard, he was visiting locations that are historically significant to the North Pole; a group of Senior Historians has asked you to accompany them as they check th...
18934359
import re import heapq from collections import Counter f = open('day1.txt', 'r') list1 = [] list2 = [] for line in f: splitLine = re.split(r"\s+", line.strip()) list1.append(int(splitLine[0])) list2.append(int(splitLine[1])) list2Count = Counter(list2) similarityScore = 0 for num in list1: if num in...
python
2024
1
2
--- Day 1: Historian Hysteria --- The Chief Historian is always present for the big Christmas sleigh launch, but nobody has seen him in months! Last anyone heard, he was visiting locations that are historically significant to the North Pole; a group of Senior Historians has asked you to accompany them as they check th...
18934359
from collections import defaultdict with open("day_01.in") as fin: data = fin.read() ans = 0 a = [] b = [] for line in data.strip().split("\n"): nums = [int(i) for i in line.split(" ")] a.append(nums[0]) b.append(nums[1]) counts = defaultdict(int) for x in b: counts[x] += 1 for x in a: an...
python
2024
1
2
--- Day 1: Historian Hysteria --- The Chief Historian is always present for the big Christmas sleigh launch, but nobody has seen him in months! Last anyone heard, he was visiting locations that are historically significant to the North Pole; a group of Senior Historians has asked you to accompany them as they check th...
18934359
input = open("Day 1\input.txt", "r") list1 = [] list2 = [] for line in input: nums = line.split(" ") list1.append(int(nums[0])) list2.append(int(nums[-1])) list1.sort() list2.sort() total = 0 for i in range(len(list1)): num1 = list1[i] simscore = 0 for j in range(len(list2)): num2 = list...
python
2024
3
1
--- Day 3: Mull It Over --- "Our computers are having issues, so I have no idea if we have any Chief Historians in stock! You're welcome to check the warehouse, though," says the mildly flustered shopkeeper at the North Pole Toboggan Rental Shop. The Historians head out to take a look. The shopkeeper turns to you. "A...
170807108
import re def runOps(ops: str) -> int: # I am not proud of this ew = ops[4:-1].split(',') return int(ew[0]) * int(ew[1]) def part1(): with open("./input.txt") as f: pattern = re.compile("mul\\(\\d+,\\d+\\)") ops = re.findall(pattern, f.read()) sum: int = 0 for o in ops...
python
2024
3
1
--- Day 3: Mull It Over --- "Our computers are having issues, so I have no idea if we have any Chief Historians in stock! You're welcome to check the warehouse, though," says the mildly flustered shopkeeper at the North Pole Toboggan Rental Shop. The Historians head out to take a look. The shopkeeper turns to you. "A...
170807108
#!/usr/bin/python3 import re with open("input.txt") as file: instructions_cor = file.read() instructions = re.findall(r"mul\(([0-9]+,[0-9]+)\)", instructions_cor) mul_inp = [instruction.split(",") for instruction in instructions] mul_results = [int(instruction[0]) * int(instruction[1]) for instruction in mul_i...
python
2024
3
1
--- Day 3: Mull It Over --- "Our computers are having issues, so I have no idea if we have any Chief Historians in stock! You're welcome to check the warehouse, though," says the mildly flustered shopkeeper at the North Pole Toboggan Rental Shop. The Historians head out to take a look. The shopkeeper turns to you. "A...
170807108
import re def read_input_file(file_name): a = [] with open(file_name, "r") as file: for line in file: values = line.strip().split() a.append(values) return a def main(): max = 0 text = read_input_file('input.txt') pattern = r"mul\((\d+),(\d+)\)" for line in...
python
2024
3
1
--- Day 3: Mull It Over --- "Our computers are having issues, so I have no idea if we have any Chief Historians in stock! You're welcome to check the warehouse, though," says the mildly flustered shopkeeper at the North Pole Toboggan Rental Shop. The Historians head out to take a look. The shopkeeper turns to you. "A...
170807108
import re with open('input.txt', 'r') as file: input = file.read() pattern = r"mul\(\d{1,3},\d{1,3}\)" matches = re.findall(pattern, input) sum = 0 for match in matches: sum += eval(match.replace("mul(", "").replace(")", "").replace(",", "*")) print(sum)
python
2024
3
1
--- Day 3: Mull It Over --- "Our computers are having issues, so I have no idea if we have any Chief Historians in stock! You're welcome to check the warehouse, though," says the mildly flustered shopkeeper at the North Pole Toboggan Rental Shop. The Historians head out to take a look. The shopkeeper turns to you. "A...
170807108
import re import sys input_path = sys.argv[1] if len(sys.argv) > 1 else "input.txt" with open(input_path) as f: text = f.read() pattern = r"mul\(\d+,\d+\)" matches = re.findall(pattern, text) p2 = r"\d+" # print(matches) result = 0 for match in matches: nums = re.findall(p2, match) result += int(nums[0])...
python
2024
3
2
--- Day 3: Mull It Over --- "Our computers are having issues, so I have no idea if we have any Chief Historians in stock! You're welcome to check the warehouse, though," says the mildly flustered shopkeeper at the North Pole Toboggan Rental Shop. The Historians head out to take a look. The shopkeeper turns to you. "A...
74838033
import re with open("day3.txt", "r") as f: data = f.read().splitlines() pattern = r"mul\((\d+),(\d+)\)|do\(\)|don't\(\)" sum = 0 current = 1 for row in data: match = re.finditer( pattern, row, ) for mul in match: command = mul.group(0) if command == "do()": ...
python
2024
3
2
--- Day 3: Mull It Over --- "Our computers are having issues, so I have no idea if we have any Chief Historians in stock! You're welcome to check the warehouse, though," says the mildly flustered shopkeeper at the North Pole Toboggan Rental Shop. The Historians head out to take a look. The shopkeeper turns to you. "A...
74838033
from re import findall with open("input.txt") as input_file: input_text = input_file.read() total = 0 do = True for res in findall(r"mul\((\d+),(\d+)\)|(don't\(\))|(do\(\))", input_text): if do and res[0]: total += int(res[0]) * int(res[1]) elif do and res[2]: do = False elif (not do) a...
python
2024
3
2
--- Day 3: Mull It Over --- "Our computers are having issues, so I have no idea if we have any Chief Historians in stock! You're welcome to check the warehouse, though," says the mildly flustered shopkeeper at the North Pole Toboggan Rental Shop. The Historians head out to take a look. The shopkeeper turns to you. "A...
74838033
import re def sumInstructions(instructions): return sum([int(x) * int(y) for x, y in instructions]) def getTuples(instructions): return re.findall(r'mul\(([0-9]{1,3}),([0-9]{1,3})\)', instructions) def main(): total = 0 with open('input.txt') as input: line = input.read() split = re.s...
python
2024
3
2
--- Day 3: Mull It Over --- "Our computers are having issues, so I have no idea if we have any Chief Historians in stock! You're welcome to check the warehouse, though," says the mildly flustered shopkeeper at the North Pole Toboggan Rental Shop. The Historians head out to take a look. The shopkeeper turns to you. "A...
74838033
import re from functools import reduce pattern = r'mul\(\d{1,3},\d{1,3}\)|do\(\)|don\'t\(\)' num_pattern = r'\d{1,3}' with open('input.txt', 'r') as f: data = f.read() print(data) matches = re.findall(pattern, data) res = 0 doCompute = True for match in matches: print(match) if...
python
2024
3
2
--- Day 3: Mull It Over --- "Our computers are having issues, so I have no idea if we have any Chief Historians in stock! You're welcome to check the warehouse, though," says the mildly flustered shopkeeper at the North Pole Toboggan Rental Shop. The Historians head out to take a look. The shopkeeper turns to you. "A...
74838033
import re with open('input.txt', 'r') as file: input = file.read() do_pattern = r"do\(\)" dont_pattern = r"don't\(\)" do_matches = re.finditer(do_pattern, input) dont_matches = re.finditer(dont_pattern, input) do_indexes = [x.start() for x in do_matches] dont_indexes = [x.start() for x i...
python
2024
4
1
--- Day 4: Ceres Search --- "Looks like the Chief's not here. Next!" One of The Historians pulls out a device and pushes the only button on it. After a brief flash, you recognize the interior of the Ceres monitoring station! As the search for the Chief continues, a small Elf who lives on the station tugs on your shir...
2434
DIRECTIONS = [ (1, 0), (0, 1), (-1, 0), (0, -1), (1, 1), (-1, -1), (-1, 1), (1, -1), ] def count_xmas(x, y): count = 0 for dx, dy in DIRECTIONS: if all( 0 <= x + i * dx < width and 0 <= y + i * dy < height and words[x + i * dx][y + i *...
python
2024
4
1
--- Day 4: Ceres Search --- "Looks like the Chief's not here. Next!" One of The Historians pulls out a device and pushes the only button on it. After a brief flash, you recognize the interior of the Ceres monitoring station! As the search for the Chief continues, a small Elf who lives on the station tugs on your shir...
2434
from typing import List import pprint INPUT_FILE: str = "input.txt" def readInput() -> List[List[str]]: with open(INPUT_FILE, 'r') as f: lines = f.readlines() return [list(line.strip()) for line in lines] def search2D(grid, row, col, word): # Directions: right, down, left, up, diagonal down-r...
python
2024
4
1
--- Day 4: Ceres Search --- "Looks like the Chief's not here. Next!" One of The Historians pulls out a device and pushes the only button on it. After a brief flash, you recognize the interior of the Ceres monitoring station! As the search for the Chief continues, a small Elf who lives on the station tugs on your shir...
2434
with open("./day_04.in") as fin: lines = fin.read().strip().split("\n") n = len(lines) m = len(lines[0]) # Generate all directions dd = [] for dx in range(-1, 2): for dy in range(-1, 2): if dx != 0 or dy != 0: dd.append((dx, dy)) # dd = [(-1, -1), (-1, 0), (-1, 1), # (0, -1), ...
python
2024
4
1
--- Day 4: Ceres Search --- "Looks like the Chief's not here. Next!" One of The Historians pulls out a device and pushes the only button on it. After a brief flash, you recognize the interior of the Ceres monitoring station! As the search for the Chief continues, a small Elf who lives on the station tugs on your shir...
2434
import time def solve_part_1(text: str): word = "XMAS" matrix = [ [x for x in line.strip()] for line in text.splitlines() if line.strip() != "" ] rows, cols = len(matrix), len(matrix[0]) word_length = len(word) directions = [ (0, 1), # Right (1, 0), # Down (0...
python
2024
4
1
--- Day 4: Ceres Search --- "Looks like the Chief's not here. Next!" One of The Historians pulls out a device and pushes the only button on it. After a brief flash, you recognize the interior of the Ceres monitoring station! As the search for the Chief continues, a small Elf who lives on the station tugs on your shir...
2434
from re import findall with open("input.txt") as input_file: input_text = input_file.read().splitlines() num_rows = len(input_text) num_cols = len(input_text[0]) total = 0 # Rows for row in input_text: total += len(findall(r"XMAS", row)) total += len(findall(r"XMAS", row[::-1])) # Columns for col_idx in...
python
2024
4
2
--- Day 4: Ceres Search --- "Looks like the Chief's not here. Next!" One of The Historians pulls out a device and pushes the only button on it. After a brief flash, you recognize the interior of the Ceres monitoring station! As the search for the Chief continues, a small Elf who lives on the station tugs on your shir...
1835
FNAME = "data.txt" WORD = "MMASS" def main(): matrix = file_to_matrix(FNAME) print(count_word(matrix, WORD)) def file_to_matrix(fname: str) -> list[list]: out = [] fopen = open(fname, "r") for line in fopen: out.append([c for c in line if c != "\n"]) return out def count_word(matrix:...
python
2024
4
2
--- Day 4: Ceres Search --- "Looks like the Chief's not here. Next!" One of The Historians pulls out a device and pushes the only button on it. After a brief flash, you recognize the interior of the Ceres monitoring station! As the search for the Chief continues, a small Elf who lives on the station tugs on your shir...
1835
template = [ "S..S..S", ".A.A.A.", "..MMM.." "SAMXMAS", "..MMM.." ".A.A.A.", "S..S..S", ] def find_xmas(lines: str) -> int: total = 0 for row in range(len(lines)): for col in range(len(lines[row])): if lines[row][col] == "X": # Horizontal ...
python
2024
4
2
--- Day 4: Ceres Search --- "Looks like the Chief's not here. Next!" One of The Historians pulls out a device and pushes the only button on it. After a brief flash, you recognize the interior of the Ceres monitoring station! As the search for the Chief continues, a small Elf who lives on the station tugs on your shir...
1835
# PROMPT # ----------------------------------------------------------------------------- # As the search for the Chief continues, a small Elf who lives on the # station tugs on your shirt; she'd like to know if you could help her # with her word search (your puzzle input). She only has to find one word: XMAS. # This...
python
2024
4
2
--- Day 4: Ceres Search --- "Looks like the Chief's not here. Next!" One of The Historians pulls out a device and pushes the only button on it. After a brief flash, you recognize the interior of the Ceres monitoring station! As the search for the Chief continues, a small Elf who lives on the station tugs on your shir...
1835
import re def get_grids_3x3(grid, grid_len): subgrids = [] for row_start in range(grid_len - 2): for col_start in range(grid_len - 2): subgrid = [row[col_start:col_start + 3] for row in grid[row_start:row_start + 3]] subgrids.append(subgrid) return subgrids input = [line.s...
python
2024
4
2
--- Day 4: Ceres Search --- "Looks like the Chief's not here. Next!" One of The Historians pulls out a device and pushes the only button on it. After a brief flash, you recognize the interior of the Ceres monitoring station! As the search for the Chief continues, a small Elf who lives on the station tugs on your shir...
1835
cont = [list(i.strip()) for i in open("day4input.txt").readlines()] def get_neighbors(matrix, x, y): rows = len(matrix) cols = len(matrix[0]) neighbors = [] directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0,0), (0, 1), (1, -1), (1, 0), (1, 1)] for dx, dy in directions: nx, ny = x ...
python
2024
5
1
--- Day 5: Print Queue --- Satisfied with their search on Ceres, the squadron of scholars suggests subsequently scanning the stationery stacks of sub-basement 17. The North Pole printing department is busier than ever this close to Christmas, and while The Historians continue their search of this historically signifi...
4766
page_pairs = {} page_updates = [] def main(): read_puzzle_input() check_page_updates() def read_puzzle_input(): with open('puzzle-input.txt', 'r') as puzzle_input: for line in puzzle_input: if "|" in line: page_pair = line.strip().split("|") if page_pa...
python
2024
5
1
--- Day 5: Print Queue --- Satisfied with their search on Ceres, the squadron of scholars suggests subsequently scanning the stationery stacks of sub-basement 17. The North Pole printing department is busier than ever this close to Christmas, and while The Historians continue their search of this historically signifi...
4766
#!/usr/bin/python3 input_file = "./sample_input_1.txt" #input_file = "./input_1.txt" # Sample input """ 47|53 97|13 97|61 ... 75,47,61,53,29 97,61,53,29,13 75,29,13 75,97,47,61,53 61,13,29 97,13,75,29,47 """ with open(input_file, "r") as data: lines = data.readlines() rules =[] updates = [] for li...
python
2024
5
1
--- Day 5: Print Queue --- Satisfied with their search on Ceres, the squadron of scholars suggests subsequently scanning the stationery stacks of sub-basement 17. The North Pole printing department is busier than ever this close to Christmas, and while The Historians continue their search of this historically signifi...
4766
with open('input.txt', 'r') as file: rules = [] lists = [] lines = file.readlines() i = 0 #Write the rule list while len(lines[i]) > 1: rules.append(lines[i].strip().split('|')) i += 1 i += 1 #Write the "update" list while i < len(lines): lists.append(lines[...
python
2024
5
1
--- Day 5: Print Queue --- Satisfied with their search on Ceres, the squadron of scholars suggests subsequently scanning the stationery stacks of sub-basement 17. The North Pole printing department is busier than ever this close to Christmas, and while The Historians continue their search of this historically signifi...
4766
# PROMPT # ----------------------------------------------------------------------------- # Safety protocols clearly indicate that new pages for the safety manuals must be # printed in a very specific order. The notation X|Y means that if both page # number X and page number Y are to be produced as part of an update,...
python
2024
5
1
--- Day 5: Print Queue --- Satisfied with their search on Ceres, the squadron of scholars suggests subsequently scanning the stationery stacks of sub-basement 17. The North Pole printing department is busier than ever this close to Christmas, and while The Historians continue their search of this historically signifi...
4766
def checkValid(beforeDict, update): for i in range(len(update)): # for each number num = update[i] for j in range(i + 1, len(update)): # for each number after current number if not num in beforeDict: return False val = update[j] # print(f" -> checking: {be...
python
2024
5
2
--- Day 5: Print Queue --- Satisfied with their search on Ceres, the squadron of scholars suggests subsequently scanning the stationery stacks of sub-basement 17. The North Pole printing department is busier than ever this close to Christmas, and while The Historians continue their search of this historically signifi...
6257
from collections import defaultdict with open("./day_05.in") as fin: raw_rules, updates = fin.read().strip().split("\n\n") rules = [] for line in raw_rules.split("\n"): a, b = line.split("|") rules.append((int(a), int(b))) updates = [list(map(int, line.split(","))) for line in updates.s...
python
2024
5
2
--- Day 5: Print Queue --- Satisfied with their search on Ceres, the squadron of scholars suggests subsequently scanning the stationery stacks of sub-basement 17. The North Pole printing department is busier than ever this close to Christmas, and while The Historians continue their search of this historically signifi...
6257
import math from functools import cmp_to_key def compare(item1, item2): for r in rules: if (item1, item2) == (r[0], r[1]): return -1 if (item2, item1) == (r[0], r[1]): return 1 return 0 rules = [] with open("05_input.txt", "r") as f: for line in f: if line...
python
2024
5
2
--- Day 5: Print Queue --- Satisfied with their search on Ceres, the squadron of scholars suggests subsequently scanning the stationery stacks of sub-basement 17. The North Pole printing department is busier than ever this close to Christmas, and while The Historians continue their search of this historically signifi...
6257
fopen = open("data.txt", "r") order = dict() updates = [] def fix_update(order, update) -> list[int]: valid = True restricted = [] for i in range(len(update)): for record in restricted: if update[i] in record[1]: valid = False update[i], update[record[0]...
python
2024
5
2
--- Day 5: Print Queue --- Satisfied with their search on Ceres, the squadron of scholars suggests subsequently scanning the stationery stacks of sub-basement 17. The North Pole printing department is busier than ever this close to Christmas, and while The Historians continue their search of this historically signifi...
6257
import functools def is_valid(update, rules): all_pages = set(update) seen_pages = set() for cur in update: if cur in rules: for n in rules[cur]: if n in all_pages and not n in seen_pages: return False seen_pages.add(cur) ...
python
2024
5
2
--- Day 5: Print Queue --- Satisfied with their search on Ceres, the squadron of scholars suggests subsequently scanning the stationery stacks of sub-basement 17. The North Pole printing department is busier than ever this close to Christmas, and while The Historians continue their search of this historically signifi...
6257
x = open("i.txt").read().split("\n\n") d = {} for n in x[0].splitlines(): x1, x2 = map(int, n.split("|")) if x1 in d: d[x1].append(x2) else: d[x1] = [x2] updates = [list(map(int, n.split(","))) for n in x[1].splitlines()] def is_valid(nums): for i, n in enumerate(nums): if n i...
python
2024
6
1
--- Day 6: Guard Gallivant --- The Historians use their fancy device again, this time to whisk you all away to the North Pole prototype suit manufacturing lab... in the year 1518! It turns out that having direct access to history is very convenient for a group of historians. You still have to be careful of time parad...
4890
def get_unique_positions(grid): n = len(grid) m = len(grid[0]) guard = (0, 0) dirs = [(-1, 0), (0, 1), (1, 0), (0, -1)] dirIndex = 0 for i in range(n): for j in range(m): if grid[i][j] == "^": guard = (i, j) dirIndex = 0 elif grid[i...
python
2024
6
1
--- Day 6: Guard Gallivant --- The Historians use their fancy device again, this time to whisk you all away to the North Pole prototype suit manufacturing lab... in the year 1518! It turns out that having direct access to history is very convenient for a group of historians. You still have to be careful of time parad...
4890
DIRECTIONS = ((-1, 0), (0, 1), (1, 0), (0, -1)) def main(): fopen = open("data.txt", "r") obstacles = set() visited = set() direction = 0 pos = (0, 0) i = -1 for line in fopen: i += 1 line = line.strip() j = -1 for c in line: j += 1 ...
python
2024
6
1
--- Day 6: Guard Gallivant --- The Historians use their fancy device again, this time to whisk you all away to the North Pole prototype suit manufacturing lab... in the year 1518! It turns out that having direct access to history is very convenient for a group of historians. You still have to be careful of time parad...
4890
def get_next_pos(pos, direction): if direction == 'v': return (pos[0] + 1, pos[1]) elif direction == '^': return (pos[0] - 1, pos[1]) elif direction == '<': return (pos[0], pos[1] - 1) else: return (pos[0], pos[1] + 1) def get_next_direction(direction): if di...
python
2024
6
1
--- Day 6: Guard Gallivant --- The Historians use their fancy device again, this time to whisk you all away to the North Pole prototype suit manufacturing lab... in the year 1518! It turns out that having direct access to history is very convenient for a group of historians. You still have to be careful of time parad...
4890
from enum import Enum class Direction(Enum): UP = ("^", (-1, 0)) DOWN = ("v", (1, 0)) LEFT = ("<", (0, -1)) RIGHT = (">", (0, 1)) def next(self): if self == Direction.UP: return Direction.RIGHT if self == Direction.RIGHT: return Direction.DOWN if...
python
2024
6
1
--- Day 6: Guard Gallivant --- The Historians use their fancy device again, this time to whisk you all away to the North Pole prototype suit manufacturing lab... in the year 1518! It turns out that having direct access to history is very convenient for a group of historians. You still have to be careful of time parad...
4890
l = open("i.txt").read().strip().splitlines() cord= () for i,x in enumerate(l): for j,c in enumerate(x): if c == "^": cord = (i,j) l = [list(line) for line in l] l[cord[0]][cord[1]] = '.' def in_bounds(grid, r, c): return 0 <= r < len(grid) and 0 <= c < len(grid[0]) DIRECTIONS...
python
2024
6
2
--- Day 6: Guard Gallivant --- The Historians use their fancy device again, this time to whisk you all away to the North Pole prototype suit manufacturing lab... in the year 1518! It turns out that having direct access to history is very convenient for a group of historians. You still have to be careful of time parad...
1995
import time l = open("i.txt").read().strip().splitlines() cord= () for i,x in enumerate(l): for j,c in enumerate(x): if c == "^": cord = (i,j) l = [list(line) for line in l] l[cord[0]][cord[1]] = '.' def in_bounds(grid, r, c): return 0 <= r < len(grid) and 0 <= c < len(grid[0]) ...
python
2024
6
2
--- Day 6: Guard Gallivant --- The Historians use their fancy device again, this time to whisk you all away to the North Pole prototype suit manufacturing lab... in the year 1518! It turns out that having direct access to history is very convenient for a group of historians. You still have to be careful of time parad...
1995
from enum import IntEnum, auto from dataclasses import dataclass, field in_date = "" with open("input.txt") as f: in_date = f.read() class Direction(IntEnum): Up = auto() Right = auto() Down = auto() Left = auto() @dataclass class Position: x: int y: int @dataclass class Guardian: ...
python
2024
6
2
--- Day 6: Guard Gallivant --- The Historians use their fancy device again, this time to whisk you all away to the North Pole prototype suit manufacturing lab... in the year 1518! It turns out that having direct access to history is very convenient for a group of historians. You still have to be careful of time parad...
1995
def print_grid(grid): for row in grid: for val in row: print(val, end=' ') print() def get_possible_obstacles(grid): n = len(grid) m = len(grid[0]) gr = 0 gc = 0 dirs = [(-1, 0), (0, 1), (1, 0), (0, -1)] dirIndex = 0 for i in range(n): for j in range(...
python
2024
6
2
--- Day 6: Guard Gallivant --- The Historians use their fancy device again, this time to whisk you all away to the North Pole prototype suit manufacturing lab... in the year 1518! It turns out that having direct access to history is very convenient for a group of historians. You still have to be careful of time parad...
1995
def get_positions(data: list[list[str]]) -> set[tuple[int, int]]: """ Return all positions (row and column indexes) that guard will visit before going out of bounds. """ # First value signifies row, second value signifies column, # negative values move up/left, and positive down/right directions...
python
2024
6
2
--- Day 6: Guard Gallivant --- The Historians use their fancy device again, this time to whisk you all away to the North Pole prototype suit manufacturing lab... in the year 1518! It turns out that having direct access to history is very convenient for a group of historians. You still have to be careful of time parad...
1995
def get_next_pos(pos, direction): if direction == 'v': return (pos[0] + 1, pos[1]) elif direction == '^': return (pos[0] - 1, pos[1]) elif direction == '<': return (pos[0], pos[1] - 1) else: return (pos[0], pos[1] + 1) def get_next_direction(direction): if di...
python
2024
7
1
--- Day 7: Bridge Repair --- The Historians take you to a familiar rope bridge over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side? When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty f...
1298103531759
import math from itertools import product class Solution: def calibration_result(self) ->int: result = 0 dict = {} with open("test.txt", 'r') as fd: for line in fd: line_parsed = line.strip().split(":") key = int(line_parsed[0]) values = list(map(int, line_parsed[1].strip().split())) dict[key...
python
2024
7
1
--- Day 7: Bridge Repair --- The Historians take you to a familiar rope bridge over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side? When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty f...
1298103531759
data = [] with open("i.txt") as f: for line in f: key, values = line.strip().split(":") key = int(key) values = [int(x) for x in values.strip().split()] data.append((key,values)) p1 = 0 for res,nums in data: sv = nums[0] def solve(numbers, operators): result = n...
python
2024
7
1
--- Day 7: Bridge Repair --- The Historians take you to a familiar rope bridge over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side? When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty f...
1298103531759
def main(): result = 0 with open('input.txt') as infile: for line in infile: answer, terms = line.split(': ') answer = int(answer) terms = [int(x) for x in terms.split(' ')] if find_solution(answer, terms): result += answer print(resul...
python
2024
7
1
--- Day 7: Bridge Repair --- The Historians take you to a familiar rope bridge over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side? When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty f...
1298103531759
f = open("day7.txt") def findEquation(numbers, curr_value, curr_index, test_value): if curr_value == test_value and curr_index == len(numbers): return True if curr_index >= len(numbers): return False first = findEquation(numbers, curr_value + numbers[curr_index], ...
python
2024
7
1
--- Day 7: Bridge Repair --- The Historians take you to a familiar rope bridge over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side? When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty f...
1298103531759
def is_valid(target, sum_so_far, vals): if len(vals) == 0: return target == sum_so_far return is_valid(target, sum_so_far + vals[0], vals[1:]) or is_valid(target, sum_so_far * vals[0], vals[1:]) with open('input.txt') as f: lines = f.read().splitlines() total = 0 for line in lin...
python
2024
7
2
--- Day 7: Bridge Repair --- The Historians take you to a familiar rope bridge over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side? When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty f...
140575048428831
from itertools import product def eval_expr(operations, numbers): numbers = numbers.split(" ") equation = "" for i in range(len(numbers)): equation += numbers[i] if i < len(numbers) - 1: # Add an operator between numbers equation += operations[i % len(operations)] num...
python
2024
7
2
--- Day 7: Bridge Repair --- The Historians take you to a familiar rope bridge over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side? When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty f...
140575048428831
data = [] with open("i.txt") as f: for line in f: key, values = line.strip().split(":") key = int(key) values = [int(x) for x in values.strip().split()] data.append((key,values)) p2 = 0 for res, nums in data: def solve(numbers, operators): result = numbers[0] i =...
python
2024
7
2
--- Day 7: Bridge Repair --- The Historians take you to a familiar rope bridge over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side? When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty f...
140575048428831
from typing import List, Tuple from part1 import read_input, sum_valid_expressions if __name__ == "__main__": expressions = read_input('input.txt') print( sum_valid_expressions(expressions, ['+', '*', '||']))
python
2024
7
2
--- Day 7: Bridge Repair --- The Historians take you to a familiar rope bridge over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side? When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty f...
140575048428831
#!/usr/bin/python3 from array import array import sys def calc(operator,ans,target,x): if len(x)>0: #print(f"Calc ({operator},{ans},{target},{x}") #print(f"{len(x)}: ",end='') if operator=='+': ans = ans + x[0] #print(f"Adding got {ans}") elif operator=='*': ...
python
2024
7
2
--- Day 7: Bridge Repair --- The Historians take you to a familiar rope bridge over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side? When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty f...
140575048428831
from itertools import product with open("./day_07.in") as fin: lines = fin.read().strip().split("\n") ans = 0 for i, line in enumerate(lines): parts = line.split() value = int(parts[0][:-1]) nums = list(map(int, parts[1:])) def test(combo): ans = nums[0] for i in range(1, len(nums...
python
2024
8
1
--- Day 8: Resonant Collinearity --- You find yourselves on the roof of a top-secret Easter Bunny installation. While The Historians do their thing, you take a look at the familiar huge antenna. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter...
332
import math def main(): antennas = {} grid_width = 0 grid_height = 0 with open('input.txt') as infile: y = 0 for line in infile: x = 0 for c in line.rstrip('\n'): if c != '.': if c in antennas: antennas[...
python
2024
8
1
--- Day 8: Resonant Collinearity --- You find yourselves on the roof of a top-secret Easter Bunny installation. While The Historians do their thing, you take a look at the familiar huge antenna. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter...
332
from collections import defaultdict from itertools import combinations with open("./day_08.in") as fin: grid = fin.read().strip().split("\n") n = len(grid) def in_bounds(x, y): return 0 <= x < n and 0 <= y < n def get_antinodes(a, b): ax, ay = a bx, by = b cx, cy = ax - (bx - ax), ay - (by ...
python
2024
8
1
--- Day 8: Resonant Collinearity --- You find yourselves on the roof of a top-secret Easter Bunny installation. While The Historians do their thing, you take a look at the familiar huge antenna. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter...
332
import re from itertools import combinations contents = open("day08.txt").readlines() # Part 1 pattern = "[^.]" antennas = {} antinodes = [] for i in range(len(contents)): line = contents[i].strip() while re.search(pattern, line): match = re.search(pattern, line) line = line[:match.span()[0]]...
python
2024
8
1
--- Day 8: Resonant Collinearity --- You find yourselves on the roof of a top-secret Easter Bunny installation. While The Historians do their thing, you take a look at the familiar huge antenna. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter...
332
input = open("day_08\input.txt", "r").read().splitlines() column_length = len(input) row_length = len(input[0]) antenna_map = {} antinodes = set() for i in range(column_length): for j in range(row_length): if not input[i][j] == ".": try: antenna_map[input[i][j]] += [(i, j)] except...
python
2024
8
1
--- Day 8: Resonant Collinearity --- You find yourselves on the roof of a top-secret Easter Bunny installation. While The Historians do their thing, you take a look at the familiar huge antenna. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter...
332
EMPTY_CELL = '.' ANTINODE_CELL = '#' class Grid: def __init__(self, cells): self.cells = cells self.height = len(cells) self.width = len(cells[0]) if self.height > 0 else 0 self.antinode_locations = set() def __str__(self): return '\n'.join(''.join(row) for row in self.cells) def __repr__(self): retur...
python
2024
8
2
--- Day 8: Resonant Collinearity --- You find yourselves on the roof of a top-secret Easter Bunny installation. While The Historians do their thing, you take a look at the familiar huge antenna. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter...
1174
from itertools import combinations from typing import Set, Tuple import re with open("day8.input", "r") as file: s = file.read().strip() ans = 0 g = [list(r) for r in s.split("\n")] height, width = len(g), len(g[0]) def check(coord: Tuple[int, int]) -> bool: y, x = coord return 0 <= y < height and 0 <= ...
python
2024
8
2
--- Day 8: Resonant Collinearity --- You find yourselves on the roof of a top-secret Easter Bunny installation. While The Historians do their thing, you take a look at the familiar huge antenna. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter...
1174
EMPTY_CELL = '.' ANTINODE_CELL = '#' class Grid: def __init__(self, cells): self.cells = cells self.height = len(cells) self.width = len(cells[0]) if self.height > 0 else 0 self.antinode_locations = set() def __str__(self): return '\n'.join(''.join(row) for row in self.cells) def __repr__(self): retur...
python
2024
8
2
--- Day 8: Resonant Collinearity --- You find yourselves on the roof of a top-secret Easter Bunny installation. While The Historians do their thing, you take a look at the familiar huge antenna. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter...
1174
f = open("input.txt", "r") space =[[elem for elem in line.strip()] for line in f.readlines()] dictionary = {} for i in range(0, len(space[0])): for j in range(0, len(space)): if space[j][i] == ".": continue if space[j][i] in dictionary: dictionary[space[j][i]].append((j, i))...
python
2024
8
2
--- Day 8: Resonant Collinearity --- You find yourselves on the roof of a top-secret Easter Bunny installation. While The Historians do their thing, you take a look at the familiar huge antenna. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter...
1174
from collections import defaultdict file = open("day8.txt", "r") char_to_coord_map = defaultdict(list) i = 0 for line in file: line = line.strip() j = 0 for c in line: if c != '.' and not c.isspace(): char_to_coord_map[c].append((i, j)) j += 1 i += 1 m = i n = j def che...
python
2024
8
2
--- Day 8: Resonant Collinearity --- You find yourselves on the roof of a top-secret Easter Bunny installation. While The Historians do their thing, you take a look at the familiar huge antenna. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter...
1174
def read_input(filename): with open(filename, 'r') as f: return [line.strip() for line in f.readlines()] def find_antennas(grid): antennas = {} for y in range(len(grid)): for x in range(len(grid[y])): char = grid[y][x] if char != '.': if char not in a...
python
2024
9
1
--- Day 9: Disk Fragmenter --- Another push of the button leaves you in the familiar hallways of some friendly amphipods! Good thing you each somehow got your own personal mini submarine. The Historians jet away in search of the Chief, mostly by driving directly into walls. While The Historians quickly figure out how...
6421128769094
with open("input.txt") as input_file: input_text = input_file.read().splitlines() file_structure = [ (i // 2 if not i % 2 else -1, int(x)) for i, x in enumerate(input_text[0]) ] # File ID -1 means free space buffer = None total = 0 current_index = 0 while file_structure: file_id, length = file_structure....
python
2024
9
1
--- Day 9: Disk Fragmenter --- Another push of the button leaves you in the familiar hallways of some friendly amphipods! Good thing you each somehow got your own personal mini submarine. The Historians jet away in search of the Chief, mostly by driving directly into walls. While The Historians quickly figure out how...
6421128769094
from typing import List from pprint import pprint as pprint def readInput() -> List[List[str]]: with open("input.txt", 'r') as f: lines = f.readlines() return [int(n) for n in list(lines[0].strip())] def parseInput(input) -> List: parsed = [] inc = 0 free = False for i in inpu...
python
2024
9
1
--- Day 9: Disk Fragmenter --- Another push of the button leaves you in the familiar hallways of some friendly amphipods! Good thing you each somehow got your own personal mini submarine. The Historians jet away in search of the Chief, mostly by driving directly into walls. While The Historians quickly figure out how...
6421128769094
in_date = "" with open("input.txt") as f: in_date = f.read() def map_to_blocks(array): blocks = [] for idx, num in enumerate(array): sub_blocks = [] if not idx % 2: # data block sub_blocks = [idx // 2 for _ in range(num)] else: # free block ...
python
2024
9
1
--- Day 9: Disk Fragmenter --- Another push of the button leaves you in the familiar hallways of some friendly amphipods! Good thing you each somehow got your own personal mini submarine. The Historians jet away in search of the Chief, mostly by driving directly into walls. While The Historians quickly figure out how...
6421128769094
with open("./day_09.in") as fin: line = fin.read().strip() def make_filesystem(diskmap): blocks = [] is_file = True id = 0 for x in diskmap: x = int(x) if is_file: blocks += [id] * x id += 1 is_file = False else: blocks += [No...
python
2024
9
1
--- Day 9: Disk Fragmenter --- Another push of the button leaves you in the familiar hallways of some friendly amphipods! Good thing you each somehow got your own personal mini submarine. The Historians jet away in search of the Chief, mostly by driving directly into walls. While The Historians quickly figure out how...
6421128769094
f = open("input.txt", "r") data = f.readlines()[0].strip() f.close() def createFile(line): result = [] counter = 0 for i in range(0, len(line)): if i%2 == 0: txt = [] for j in range(0, int(line[i])): txt.append(str(counter)) result.append(txt) ...
python
2024
9
2
--- Day 9: Disk Fragmenter --- Another push of the button leaves you in the familiar hallways of some friendly amphipods! Good thing you each somehow got your own personal mini submarine. The Historians jet away in search of the Chief, mostly by driving directly into walls. While The Historians quickly figure out how...
6448168620520
from typing import List from pprint import pprint as pprint class Block: def __init__(self, size: int, num: int, free: bool) -> None: self.size = size self.num = num self.free = free def __str__(self) -> str: if self.free: return f"[Size: {self.size}, Free: {sel...
python
2024
9
2
--- Day 9: Disk Fragmenter --- Another push of the button leaves you in the familiar hallways of some friendly amphipods! Good thing you each somehow got your own personal mini submarine. The Historians jet away in search of the Chief, mostly by driving directly into walls. While The Historians quickly figure out how...
6448168620520
def defrag(layout): for index in range(len(layout)-1, -1, -1): item = layout[index] if item["fileId"] == ".": continue for s in range(0, index): if layout[s]["fileId"] == ".": if layout[s]["length"] > item["length"]: remaining = lay...
python
2024
9
2
--- Day 9: Disk Fragmenter --- Another push of the button leaves you in the familiar hallways of some friendly amphipods! Good thing you each somehow got your own personal mini submarine. The Historians jet away in search of the Chief, mostly by driving directly into walls. While The Historians quickly figure out how...
6448168620520
in_date = "" with open("input.txt") as f: in_date = f.read() def map_to_blocks(array): blocks = [] for idx, num in enumerate(array): sub_blocks = [] if not idx % 2: # data block sub_blocks = [idx // 2 for _ in range(num)] else: # free block ...
python
2024
9
2
--- Day 9: Disk Fragmenter --- Another push of the button leaves you in the familiar hallways of some friendly amphipods! Good thing you each somehow got your own personal mini submarine. The Historians jet away in search of the Chief, mostly by driving directly into walls. While The Historians quickly figure out how...
6448168620520
f = open("input.txt", "r") data = f.readlines()[0].strip() f.close() def createFile(line): result = [] counter = 0 for i in range(0, len(line)): if i%2 == 0: txt = [] for j in range(0, int(line[i])): txt.append(str(counter)) result.append(txt) ...
python
2024
9
2
--- Day 9: Disk Fragmenter --- Another push of the button leaves you in the familiar hallways of some friendly amphipods! Good thing you each somehow got your own personal mini submarine. The Historians jet away in search of the Chief, mostly by driving directly into walls. While The Historians quickly figure out how...
6448168620520
with open("input.txt") as input_file: input_text = input_file.read().splitlines() file_structure = [ (i // 2 if not i % 2 else -1, int(x)) for i, x in enumerate(input_text[0]) ] current_index = len(file_structure) - (1 if file_structure[-1][0] != -1 else 2) while current_index > 0: for idx, (space_id, spac...
python
2024
10
1
--- Day 10: Hoof It --- You all arrive at a Lava Production Facility on a floating island in the sky. As the others begin to search the massive industrial complex, you feel a small nose boop your leg and look down to discover a reindeer wearing a hard hat. The reindeer is holding a book titled "Lava Island Hiking Gui...
587
from collections import deque def read_input(filename): with open(filename) as f: return [[int(x) for x in line.strip()] for line in f] def get_neighbors(grid, x, y): directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # right, down, left, up height, width = len(grid), len(grid[0]) neighbors = []...
python
2024
10
1
--- Day 10: Hoof It --- You all arrive at a Lava Production Facility on a floating island in the sky. As the others begin to search the massive industrial complex, you feel a small nose boop your leg and look down to discover a reindeer wearing a hard hat. The reindeer is holding a book titled "Lava Island Hiking Gui...
587
with open("input.txt") as input_file: input_text = input_file.read().splitlines() num_rows = len(input_text) num_cols = len(input_text[0]) topography = {} for row in range(num_rows): for col in range(num_cols): topography[(row, col)] = int(input_text[row][col]) movements = ((1, 0), (-1, 0), (0, 1), (...
python
2024
10
1
--- Day 10: Hoof It --- You all arrive at a Lava Production Facility on a floating island in the sky. As the others begin to search the massive industrial complex, you feel a small nose boop your leg and look down to discover a reindeer wearing a hard hat. The reindeer is holding a book titled "Lava Island Hiking Gui...
587
from collections import deque class Trail: def __init__(self, x, y): self.x = x self.y = y def score(self): seen = set() queue = deque() queue.append(( 0, self.x, self.y, )) while queue: val, x, y = queu...
python
2024
10
1
--- Day 10: Hoof It --- You all arrive at a Lava Production Facility on a floating island in the sky. As the others begin to search the massive industrial complex, you feel a small nose boop your leg and look down to discover a reindeer wearing a hard hat. The reindeer is holding a book titled "Lava Island Hiking Gui...
587
file = open("day10.txt", "r") starts = [] matrix = [] i = 0 for line in file: curr = [] matrix.append(curr) line = line.strip() j = 0 for c in line: num = -1 if c != '.': num = int(c) curr.append(num) if num == 0: starts.append((i, j)) ...
python
2024
10
1
--- Day 10: Hoof It --- You all arrive at a Lava Production Facility on a floating island in the sky. As the others begin to search the massive industrial complex, you feel a small nose boop your leg and look down to discover a reindeer wearing a hard hat. The reindeer is holding a book titled "Lava Island Hiking Gui...
587
f = open("input.txt", "r") data = [[elem for elem in line.strip()] for line in f] f.close() def findTrailHeads(data): trailHeads = [] for i in range(len(data)): for j in range(len(data[i])): if data[i][j] == "0": trailHeads.append((i, j)) return trailHeads TrailHeads = ...
python
2024
10
2
--- Day 10: Hoof It --- You all arrive at a Lava Production Facility on a floating island in the sky. As the others begin to search the massive industrial complex, you feel a small nose boop your leg and look down to discover a reindeer wearing a hard hat. The reindeer is holding a book titled "Lava Island Hiking Gui...
1340
def main(): # cool recursive solution credit to @jonathanpaulson5053 part2 = 0 with open('input.txt', 'r') as file: data = file.read().strip() grid = data.split('\n') rows = len(grid) cols = len(grid[0]) dp = {} def ways(r, c): if grid[r][c] == '0': ret...
python
2024
10
2
--- Day 10: Hoof It --- You all arrive at a Lava Production Facility on a floating island in the sky. As the others begin to search the massive industrial complex, you feel a small nose boop your leg and look down to discover a reindeer wearing a hard hat. The reindeer is holding a book titled "Lava Island Hiking Gui...
1340
f = open("input.txt", "r") data = [[elem for elem in line.strip()] for line in f] f.close() def findTrailHeads(data): trailHeads = [] for i in range(len(data)): for j in range(len(data[i])): if data[i][j] == "0": trailHeads.append((i, j)) return trailHeads TrailHeads = ...
python
2024
10
2
--- Day 10: Hoof It --- You all arrive at a Lava Production Facility on a floating island in the sky. As the others begin to search the massive industrial complex, you feel a small nose boop your leg and look down to discover a reindeer wearing a hard hat. The reindeer is holding a book titled "Lava Island Hiking Gui...
1340
import time file = open("input.txt", "r") start = time.time() matrix = [] trailheads = [] for line_index, line in enumerate(file.readlines()): matrix.append([]) for column_index, column in enumerate(line.replace("\n", "")): elevation = int(column) matrix[line_index].append(elevation) ...
python
2024
10
2
--- Day 10: Hoof It --- You all arrive at a Lava Production Facility on a floating island in the sky. As the others begin to search the massive industrial complex, you feel a small nose boop your leg and look down to discover a reindeer wearing a hard hat. The reindeer is holding a book titled "Lava Island Hiking Gui...
1340
from collections import deque input_file = 'input.txt' # input_file = 'example.txt' directions = [ (0, 1), (1, 0), (0, -1), (-1, 0), ] def is_inbounds(coords: tuple, arr: list) -> bool: return coords[0] >= 0 and coords[0] < len(arr) and coords[1] >= 0 and coords[1] < len(arr[0]) def bfs(trail_ma...
python
2024
10
2
--- Day 10: Hoof It --- You all arrive at a Lava Production Facility on a floating island in the sky. As the others begin to search the massive industrial complex, you feel a small nose boop your leg and look down to discover a reindeer wearing a hard hat. The reindeer is holding a book titled "Lava Island Hiking Gui...
1340
# INPUT = "input" INPUT = "test1.in" grid = [] with open(INPUT, "r") as f: lines = f.readlines() for i, line in enumerate(lines): line = line.strip() grid.append([int(c) for c in line]) h = len(grid) w = len(grid[0]) def test(grid, used, x, y, v) -> int: if not (0 <= x < w): retu...
python