#!/usr/bin/python3.8 from aoc import Input inp = Input('input12.txt', ["""F10 N3 F7 R90 F11 """]) # inp.use_test(0) navi = [(ln[0], int(ln[1:])) for ln in inp.get_valid_lines()] # It seems that L and R values are always multiples of 90 x = 0 y = 0 face = 0 directions = 'ENWS' for i, a in navi: if i == 'F': i = directions[face] if i == 'E': x += a elif i == 'N': y += a elif i == 'W': x -= a
inp = Input( 'input08.txt', ["""nop +0 acc +1 jmp +4 acc +3 jmp -3 acc -99 acc +1 jmp -4 acc +6"""]) #inp.use_test(0) program = [] for ln in inp.get_valid_lines(): instr = ln[:3] m = re.search(r'-?\d+', ln) assert (m is not None) op = int(m.group(0)) program += [[instr, op]] def run_prog(prog): acc = 0 pc = 0 visited = set() while True: if pc in visited: return (False, acc) if pc >= len(prog):