Question
A small virtual machine executes a list of instructions over one integer accumulator. Blank lines and comment lines are ignored. - `plus n`: add `n` to the accumulator and move to the next instruction. - `next n`: ignore `n` and move to the next instruction. - `jump n`: move to the instruction at `current_index + n`. Execution halts when the program counter moves outside the instruction list. It loops when it is about to execute an instruction that has already run. Exactly one `jump` or `next` instruction was swapped while keeping its operand. ## Interface ```python def find_loop_line(lines: list[str]) -> int: ... def find_wrong_instruction(lines: list[str]) -> int: ... def run_repaired(lines: list[str]) -> int: ... ``` Return `-1` from the first two functions if the original program already halts. `run_repaired` must flip the single faulty control-flow instruction, restart execution, and return the accumulator at termination. If the program already halts, return its original terminal accumulator. ## Constraints and edge cases Assume at most 200,000 parsed instructions and signed 32-bit operands. Handle comments, blank lines, negative jumps, jumps beyond either end, a loop whose revisited line is not itself faulty, and an already-terminating program. Do not mutate the caller's input. ## Staged follow-ups 1. Implement loop detection and report the first repeated instruction. 2. Identify and repair the one swapped operation efficiently. 3. Generalize to finding any single flip that makes the program halt when the faulty line is not directly implied by the first repeated target. 4. Discuss how to report malformed instructions and arithmetic overflow.