From 6ba7e729de04ac4207ad7521cc47333ac696460f Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Wed, 25 Dec 2019 00:30:26 -0500 Subject: [PATCH] Add diff since day 21 intcode for day 23 --- day23/py/intcode_changes_since_day_21.diff | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 day23/py/intcode_changes_since_day_21.diff diff --git a/day23/py/intcode_changes_since_day_21.diff b/day23/py/intcode_changes_since_day_21.diff new file mode 100644 index 0000000..a7baf01 --- /dev/null +++ b/day23/py/intcode_changes_since_day_21.diff @@ -0,0 +1,43 @@ +--- day21intcode.py 2019-12-25 00:28:32.711337297 -0500 ++++ day23intcode.py 2019-12-25 00:29:29.514744969 -0500 +@@ -1,6 +1,7 @@ + import collections + import sys +-from typing import List, Tuple, Optional ++import itertools ++from typing import Iterable, List, Tuple, Optional, TypeVar + + + # Halt indicates that the assembled program should terminate +@@ -153,10 +154,12 @@ + + + # Executes the program, returning the instruction pointer to continue at (if the program paused), the relative base, +-# and a list of all outputs that occurred during the program's execution +-def execute_program(memory: Memory, program_inputs: List[int], initial_instruction_pointer: int = 0, initial_rel_base: int = 0) -> Tuple[Optional[int], int, List[int]]: ++# and a list of all inputs/outputs that occurred during the program's execution ++# This return signature is gross but it's day 23... I'm not going to rewrite it. ++def execute_program(memory: Memory, program_inputs: List[int], initial_instruction_pointer: int = 0, initial_rel_base: int = 0) -> Tuple[Optional[int], int, List[int], List[int]]: + i = initial_instruction_pointer + input_cursor = 0 ++ consumed_inputs = [] + outputs = [] + rel_base = initial_rel_base + # Go up to the maximum address, not the number of addresses +@@ -167,8 +170,9 @@ + if operation.opcode == Operation.OPCODE_INPUT: + # If we are out of input, don't fail out, but rather just pause execution + if input_cursor >= len(program_inputs): +- return i, rel_base, outputs ++ return i, rel_base, consumed_inputs, outputs + program_input = program_inputs[input_cursor] ++ consumed_inputs.append(program_input) + input_cursor += 1 + + try: +@@ -182,4 +186,4 @@ + outputs.append(output) + + # The program is finished, and we are saying there is no instruction pointer +- return None, rel_base, outputs ++ return None, rel_base, consumed_inputs, outputs