Skip to main content

advent_of_code/year2016/
day25.rs

1use super::assembunny::{Computer, Instruction, ValueOrRegister};
2use crate::input::Input;
3
4pub fn solve(input: &Input) -> Result<u32, String> {
5    let computer = Computer::parse(input.text)?;
6    if let Instruction::Copy(ValueOrRegister::Value(a), _register) = computer.instructions[1]
7        && let Instruction::Copy(ValueOrRegister::Value(b), _register) = computer.instructions[2]
8    {
9        let start_value = a * b;
10        for initial_value in 1..1000 {
11            let value = start_value + initial_value;
12            if format!("{value:b}").replace("10", "").is_empty() {
13                return Ok(initial_value as u32);
14            }
15        }
16    }
17
18    Err("Input does not match expectations".to_string())
19}
20
21#[test]
22pub fn tests() {
23    let real_input = include_str!("day25_input.txt");
24    test_part_one!(real_input => 196);
25}