def part_1(): input_file = open("resources/07input.txt") my_prog = [int(a) for a in input_file.read().strip().split(",")] input_file.close() params1 = [0, 1, 2, 3, 4] param_sets = list(itertools.permutations(params1)) highscore = 0 for param_set in param_sets: input_vals = [0, 0] for phase in param_set: intcode = IntCode() input_vals[0] = phase intcode.input_buffer = input_vals[:] intcode.program = my_prog[:] intcode.run_program() if len(intcode.output_buffer) > 0: input_vals[1] = intcode.output_buffer[0] highscore = intcode.output_buffer[ 0] if intcode.output_buffer[0] > highscore else highscore return highscore
def part_1(): input_file = open("resources/02input.txt") prog = [int(a) for a in input_file.read().strip().split(",")] input_file.close() prog[1] = 12 prog[2] = 2 intcode = IntCode() intcode.program = prog[:] intcode.run_program() return intcode.program[0]
def gravity_assist(program, expected_result): intcode = IntCode() for noun in range(0, 99): for verb in range(0, 99): testprog = program[:] testprog[1], testprog[2] = noun, verb intcode.program = testprog intcode.run_program() result = intcode.program if result[0] == expected_result: return (noun * 100) + verb return -1, -1