def main2(): summa = 0 for line in read_input("01/input.txt"): fuel = int(line) while fuel > 0: fuel = max(int(fuel) // 3 - 2, 0) summa += fuel return summa
def main1(): chars = [] for line in read_input("02/input.txt"): chars.extend([int(i) for i in read_chars(line)]) chars[1] = 12 chars[2] = 2 intcode = process_intcode(chars) return intcode
def main2(): intcode = [] for line in read_input("02/input.txt"): intcode.extend([int(i) for i in read_chars(line)]) for i in range(0, 100): for j in range(0, 100): copy = intcode.copy() copy[1] = i copy[2] = j res = process_intcode(copy) if res[0] == 19690720: print(f"{i}, {j} are the winners!") break
import helpers lines = helpers.read_input() tree_map = [] for line in lines: tree_map.append([char for char in line]) map_width = len(tree_map[0]) def tree_on_slope(tree_map, rise, run): x, y = 0, 0 tree_count = 0 while y < len(tree_map) - 1: x += run y += rise if tree_map[y][x % map_width] == '#': tree_count += 1 return tree_count # part 1 tree_count = tree_on_slope(tree_map, 1, 3) print(f"Part 1: {tree_count}") # part 2 slopes = [ [1, 1],
import helpers import re lines = helpers.read_input('input.txt') EXPECTED_FIELDS = ['byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid', 'cid'] def parse_passport_str(passport_str): passport_dict = {} passport_str = passport_str.strip() for keyVal in passport_str.split(): key, val = keyVal.split(':') passport_dict[key] = val return passport_dict def parse_input(lines): passport_str = '' passport_list = [] for line in lines: if line == '': # end of passport passport_list.append(parse_passport_str(passport_str)) passport_str = '' else: passport_str += line + ' '
from collections import defaultdict from helpers import read_input, read_chars wire1, wire2 = [list(read_chars(line)) for line in read_input("03/input.txt")] test_wire1 = ["R8", "U5", "L5", "D3"] test_wire2 = ["U7", "R6", "D4", "L4"] test_wire3 = ["R75", "D30", "R83", "U83", "L12", "D49", "R71", "U7", "L72"] test_wire4 = ["U62", "R66", "U55", "R34", "D71", "R55", "D58", "R83"] test_wire5 = [ "R98", "U47", "R26", "D63", "R33", "U87", "L62", "D20", "R33", "U53", "R51", ] test_wire6 = ["U98", "R91", "D20", "R16", "D67", "R40", "U7", "R15", "U6", "R7"] OPS = {"R": "x + 1, y", "L": "x - 1, y", "D": "x, y - 1", "U": "x, y + 1"} WIRE_PATHS = defaultdict(dict)
def main(): summa = 0 for line in read_input("01/input.txt"): num = int(line) // 3 - 2 summa += num return summa