advent_of_code_2024

Module day_17

source
Expand description

This is my solution for Advent of Code - Day 17: Chronospatial Computer

parse_input parses the input into a Computer.

Computer::run run solves part 1, with helpers Computer::next_instruction, and Computer::deref_combo. There is also a method for each of the 8 operators.

reverse_engineer_quine solves part 2 by building up the number for a from least-significant digit backwards brute_force_quine is left as deaf code for posterity

StructsΒ§

  • Computer πŸ”’
    Represents a computer and the program it will run

FunctionsΒ§

  • Look for a quine by trying all values of A from 0
  • parse_input πŸ”’
    Parse the puzzle input, three registers, a blank line and a program represented by a list of 3-bit digits
  • parse_program πŸ”’
    Parse e.g. Program: 2,0,2,4 into vec![2,0,2,4]
  • parse_register πŸ”’
    Parse e.g. Register A: 2024 into 2024usize
  • Working from least-significant bit backwards build a bit at a time. This relies on the program having a loop where a 3-bit digit is right-shifted off the A register and corresponding single digit is outputted by the program.
  • The entry point for running the solutions with the β€˜real’ puzzle input.