from input_manager import get_input_data import intcode print(intcode.parse(get_input_data(5), [5])[-1])
from input_manager import get_input_data import math data = get_input_data(3).split() data = [wire.split(",") for wire in data] def add_coord(coord1: tuple, coord2: tuple) -> tuple: return (coord1[0] + coord2[0], coord1[1] + coord2[1]) def multiply_with_int(number: int, coord: tuple) -> tuple: return (coord[0] * number, coord[1] * number) insts = {"R": (0, 1), "L": (0, -1), "U": (1, 0), "D": (-1, 0)} positions = [set(), set()] wire_id = 0 for wire in data: current_pos = (0, 0) for part in wire: old_pos = current_pos current_pos = add_coord( current_pos, multiply_with_int(int(part[1:]), insts[part[0]])) x, y = current_pos for x in range(old_pos[0], current_pos[0], sum(insts[part[0]])): positions[wire_id].add((x, y)) for y in range(old_pos[1], current_pos[1], sum(insts[part[0]])): positions[wire_id].add((x, y)) wire_id += 1
from input_manager import get_input_data from collections import defaultdict # ["a" orbits "b"] (index 0 orbits index 1) orbits = dict( map(lambda x: x.rstrip().split(")")[::-1], get_input_data(6, True))) def distance_from_root(child): if child in orbits: return distance_from_root(orbits[child]) + 1 return 0 total_orbits = 0 for orbit in orbits: total_orbits += distance_from_root(orbit) print(total_orbits)
from input_manager import get_input_data from itertools import permutations import intcode import asyncio code = get_input_data(7) code = "3,26,1001,26,-4,26,3,27,1002,27,2,27,1,27,26,27,4,27,1001,28,-1,28,1005,28,6,99,0,0,5" async def get_input(start_value: int, output: list) -> int: yield start_value for i in output: yield i def test_modes(modes): amps = [intcode.Intcode(code) for amp in range(5)] outputs = [[0]] + [[]]*4 for i in range(len(amps)): def add_output(_output): outputs[i].append(_output[-1]) amps[i].output_callback = add_output amps[i].input_gen = get_input(modes[i], outputs[i]) for i in range(len(amps)): asyncio.run(amps[i].run()) return amps loops = set() for modes in permutations(range(5)):
from input_manager import get_input_data data = get_input_data(2) data = list(map(int, data.split(","))) data[1] = 12 data[2] = 2 instructions = {1: lambda a, b: a+b, 2: lambda a, b: a*b} for i in range(0, len(data), 4): if data[i] == 99: break instruction = instructions[data[i]] value = instruction(data[data[i+1]], data[data[i+2]]) data[data[i+3]] = value print(data[0])
from input_manager import get_input_data data = get_input_data(8).rstrip() n = 25*6 data = [data[i:i+n] for i in range(0, len(data), n)] min_layer = min(data, key=lambda x: x.count("0")) print(min_layer.count("1") * min_layer.count("2"))
def reset_memory_with_start_args(a, b): data = get_input_data(2) data = list(map(int, data.split(","))) data[1] = a data[2] = b return data
from input_manager import get_input_data data = tuple(map(int, get_input_data(4).rstrip().split("-"))) passwords = set() for password in range(*data): password = str(password) has_double = False does_not_decrease = True for i in range(len(password) - 1): if password[i] == password[i + 1]: has_double = True if password[i] > password[i + 1]: does_not_decrease = False if has_double and does_not_decrease: passwords.add(password) print(len(passwords))
from input_manager import get_input_data import math data = get_input_data(1, True) # Get the input for day one data = list(map(lambda x: int(x), data)) def get_fuel(x): return math.floor(int(x) / 3) - 2 module_fuels = [] for module in data: total_fuel = 0 current_fuel_added = module while current_fuel_added > 6: current_fuel_added = get_fuel(current_fuel_added) total_fuel += current_fuel_added module_fuels.append(total_fuel) print(sum(module_fuels))