From 8c0ff14d94a8736ee9042b49567a722f3db558d0 Mon Sep 17 00:00:00 2001 From: Keenan Tims Date: Fri, 4 Dec 2026 23:25:28 -0700 Subject: [PATCH] 2026/day5: part2 - facepalm why did i choose dfs?? --- 2026/src/day5.rs | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/2026/src/day5.rs b/2026/src/day5.rs index 237ad68..adc9d97 100644 --- a/2026/src/day5.rs +++ b/2026/src/day5.rs @@ -1,6 +1,11 @@ use aoc_runner_derive::{aoc, aoc_generator}; +use itertools::Itertools; -use std::{collections::HashMap, fmt::Display, str::FromStr}; +use std::{ + collections::{HashMap, HashSet, VecDeque}, + fmt::Display, + str::FromStr, +}; #[derive(Clone, Copy, Debug, PartialEq)] enum Button { @@ -41,12 +46,13 @@ impl Display for Button { } #[derive(Clone, Debug)] -struct Microwave { +struct Microwave { displayed: u64, } -impl Microwave { - fn press(&self, button: Button) -> Microwave { +impl Microwave { + const MAX_N: u64 = 10u64.pow(DIGITS) - 1; + fn press(&self, button: Button) -> Self { let displayed = match button { Button::Append(i) => self.displayed * 10 + i as u64, Button::Mult(i) => self.displayed * i as u64, @@ -60,7 +66,13 @@ impl Microwave { Button::Oct => format!("{:o}", self.displayed).parse().unwrap(), Button::Bksp => self.displayed / 10, }; - Self { displayed } + if displayed > Self::MAX_N { + Self { + displayed: self.displayed, + } + } else { + Self { displayed } + } } } @@ -71,7 +83,7 @@ fn parse(input: &str) -> Vec