from utils.get_inputs import ProblemParser lines = ProblemParser().load_input(2020, 8) def parse_program(): return [tuple(x.split()) for x in lines] def parse_value(value): return (value[0], int(value[1:])) def run(program): acc = 0 pointer = 0 cache = {} part1 = False looped = set() while pointer < len(program): command, value = program[pointer] sign, number = parse_value(value) if pointer in looped: acc = cache[pointer] elif pointer in cache.keys(): if not part1: print("Part1", acc) part1 = True if command == "jmp":
import sys from collections import Counter from pathlib import Path path_root = Path(__file__).parents[2] sys.path.append(str(path_root)) from utils.get_inputs import ProblemParser lines = ProblemParser().load_input(2021, 14) default_template = lines[0] rules = {} for line in lines[2:len(lines)]: part = line.split(" -> ") rules[part[0]] = part[1] print(default_template) def part1(): template = default_template updated_template = [] for n in range(10): print(n) for i in range(len(template) - 1): base = template[i:i + 2] base = rules[base] updated_template.append(base)
from collections import defaultdict, deque, namedtuple from functools import lru_cache import sys from typing import DefaultDict, Deque from utils.get_inputs import ProblemParser from pprint import pprint lines = ProblemParser().load_input(2020, 10) lines = [int(x) for x in lines] list.sort(lines) lines.append(lines[-1] + 3) lines.insert(0, 0) diffs = DefaultDict(int) i = 1 while (i < len(lines)): diffs[lines[i] - lines[i - 1]] = diffs[lines[i] - lines[i - 1]] + 1 i += 1 print(diffs[1] * diffs[3]) print("Part 2\n") def dp(): t = [0 for _ in range(max(lines) + 1)] i = 1 t[0] = 1 if 1 in lines: