Your question is Find Infinite Loop Instruction. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Anthropic Claude Code uses a small deterministic instruction stream during an internal execution check. Given the instructions and initial register values, determine whether execution terminates or enters an infinite loop. If it loops, return the index of the first instruction in the repeating cycle. Otherwise, return -1.
A machine state consists of the program counter and the values of registers a, b, and c. Tracking only the program counter is incorrect because the same instruction can be reached with different register values.
Implement find_infinite_loop(instructions, initial). instructions is a list of instruction arrays. initial is a dictionary containing integer values for a, b, and c. Register values use unsigned 8-bit arithmetic, so every set and add result is reduced modulo 256.
Supported instructions are ['set', register, value], ['add', register, value], ['jmp', offset], ['jnz', register, offset], and ['halt']. The program counter starts at 0. A jump offset is relative to the current instruction. Reaching halt or moving outside the instruction list terminates execution.
def find_infinite_loop(instructions, initial):