Log in to get your input and submit your answers.
Day 08: Boot Sequence
Panic is spreading across the cluster: the iMacs won't boot! The screen flashes an Apple logo for a few seconds before shutting down and looping endlessly.
You hook your laptop up to one of the Macs via a serial cable and manage to extract the boot sequence (your puzzle input). The code is written in an assembly dialect that vaguely resembles Corewar.
The processor executes one instruction per line. There are three types of instructions:
acc(accumulator): increases or decreases a single global register (which starts at 0), then proceeds to the next instruction.jmp(jump): jumps to a new instruction relative to itself.jmp +2skips the next instruction,jmp -1goes back to the previous one.nop(no operation): does nothing and simply moves to the next instruction.
Part 1
The issue is glaring: the program is stuck in an infinite loop. It never reaches the end of the file and just keeps running the same sequence of instructions over and over.
Example
Consider this small test program:
nop +0
acc +1
jmp +4
acc +3
jmp -3
acc -99
acc +1
jmp -4
acc +6Here is how it executes, step by step:
- Line 1:
nop +0— Does nothing. (Accumulator = 0) - Line 2:
acc +1— Accumulator increases to 1. - Line 3:
jmp +4— Jumps 4 lines down (to line 7). - Line 7:
acc +1— Accumulator increases to 2. - Line 8:
jmp -4— Jumps 4 lines up (to line 4). - Line 4:
acc +3— Accumulator increases to 5. - Line 5:
jmp -3— Jumps 3 lines up (to line 2). - Line 2:
acc +1— STOP! This is an instruction we have already executed.
Right before the program runs line 2 for the second time, the accumulator was 5.
Run your own boot sequence through a simulator. What is the value of the accumulator immediately before any instruction is executed a second time?