1use crate::assembunny::Interpreter;
2use std::collections::HashSet;
3use std::ops::ControlFlow;
4use utils::prelude::*;
5
6#[derive(Clone, Debug)]
24pub struct Day25 {
25 interpreter: Interpreter<false, true>,
26}
27
28impl Day25 {
29 pub fn new(input: &str, _: InputType) -> Result<Self, InputError> {
30 Ok(Self {
31 interpreter: Interpreter::new(input)?,
32 })
33 }
34
35 #[must_use]
36 pub fn part1(&self) -> i32 {
37 let mut seen = HashSet::new();
38 for i in 1..=i32::MAX {
39 let mut last = 1;
40 let mut found_solution = false;
41 seen.clear();
42
43 self.interpreter.execute([i, 0, 0, 0], |v, state| {
44 if (last == 1 && v != 0) || (last == 0 && v != 1) {
45 return ControlFlow::Break(());
46 }
47 last = v;
48
49 if seen.insert((v, state)) {
50 ControlFlow::Continue(())
51 } else {
52 found_solution = true;
54 ControlFlow::Break(())
55 }
56 });
57
58 if found_solution {
59 return i;
60 }
61 }
62
63 panic!("no solution found")
64 }
65
66 #[must_use]
67 pub fn part2(&self) -> &'static str {
68 "🎄"
69 }
70}
71
72examples!(Day25 -> (i32, &'static str) []);