Log in to get your input and submit your answers.
Day 14: Docking Data
After traveling on the bus, you realize your laptop can no longer synchronize its data bus with the school's central server.
The communication protocol uses a data bus equipped with a 24-bit binary mask. Your puzzle input contains the raw instruction stream transmitted by the system.
Two types of instructions appear in the stream:
mask = ...: defines the active bitmask (a 24-character string composed of0,1, andX).mem[address] = value: writes an integer value into a specific memory address.
Part 1
In version 1 of the protocol, the mask is applied directly to the value before writing it to memory:
- If the mask bit is
1, the corresponding bit of the value is overwritten with 1. - If the mask bit is
0, the corresponding bit of the value is overwritten with 0. - If the mask bit is
X, the corresponding bit of the value is left unchanged.
Example
Consider this short instruction sequence:
mask = XXXXXXXXXXXXXXXXX1XXXX0X
mem[8] = 11
mem[7] = 101
mem[8] = 0Execution trace:
- For
mem[8] = 11: 11 in binary is1011. With the mask, bit position 6 becomes 1 and bit position 1 becomes 0, resulting in 73 written to address 8. - For
mem[7] = 101: 101 becomes 101 written to address 7. - For
mem[8] = 0: 0 becomes 64, overwriting the previous value at address 8.
At the end of this example, the sum of all values left in memory is 101 + 64 = 165.
Execute your full input stream. What is the sum of all values left in memory after the initialization program completes?