def part_1(loc=DEFAULT_INPUT): with open(loc) as f: memory = list(map(int, f.readline().rstrip().split(','))) #jump if (not A) or (not C and D) instructions = ['OR A J', 'AND C J', 'NOT J J', 'AND D J', 'WALK'] ic = IntCode(memory) for inst in instructions: ic.add_ascii_inputs(inst) return ic.run_through()[-1]
def part_2(loc=DEFAULT_INPUT): with open(loc) as f: memory = list(map(int, f.readline().rstrip().split(','))) instructions = [ 'OR A J', 'AND B J', 'AND C J', 'NOT J J', 'OR E T', 'OR H T', 'AND T J', 'AND D J', 'RUN' ] ic = IntCode(memory) for inst in instructions: ic.add_ascii_inputs(inst) return ic.run_through()[-1]
def part_2(loc=DEFAULT_INPUT): with open(loc) as f: memory = list(map(int, f.readline().rstrip().split(','))) #moves solved by hand for given input moves = 'A,B,A,A,B,C,B,C,C,B' func_a = 'L,12,R,8,L,6,R,8,L,6' func_b = 'R,8,L,12,L,12,R,8' func_c = 'L,6,R,6,L,12' memory[0] = 2 ic = IntCode(memory) ic.add_ascii_inputs(moves) ic.add_ascii_inputs(func_a) ic.add_ascii_inputs(func_b) ic.add_ascii_inputs(func_c) ic.add_ascii_inputs('n') return ic.run_through()[-1]