From 62a671bc5a77a1a0f5b82722de55c351cd991d2f Mon Sep 17 00:00:00 2001 From: Sebastian Tobie Date: Tue, 17 Dec 2024 22:16:01 +0100 Subject: [PATCH] no real progress with day 17 --- days/2024/17.rs | 30 ++++++++++++++++++++---------- examples/2024/17.txt | 5 +++++ 2 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 examples/2024/17.txt diff --git a/days/2024/17.rs b/days/2024/17.rs index 7260127..e70cd18 100644 --- a/days/2024/17.rs +++ b/days/2024/17.rs @@ -1,7 +1,7 @@ use advent_of_code::strings::{convert_to_array, parsenumber}; #[allow(unused_imports)] use advent_of_code_macros::{include_data, include_example}; -use log::debug; +use log::*; use thousands::Separable; include_data!(DATA 2024 17); @@ -92,6 +92,14 @@ impl GenericCPU { _ => unreachable!(), } } + + fn reset(&mut self) { + self.a = 0; + self.b = 0; + self.c = 0; + self.pos = 0; + self.output.clear(); + } } fn get_content(i: &str) -> String { @@ -129,22 +137,24 @@ fn main() { let output = mem.output.iter().map(|x| x.to_string()).collect::>().join(","); println!("output: {}", output); let mut n: u64 = 0; - 'numloop: for (pos, num) in mem.ops.iter().cloned().enumerate().map(|(x, y)| (x * 3, y)) { - for i in 0..8 { - if round(i) == num { - println!("Adding {:>18}, the source of {}", i, num); + 'numloop: for (pos, num) in mem.ops.iter().enumerate().map(|(x, y)| (x * 3, *y)).rev() { + for i in 0..64 { + println!("Testing round({}) == {}", ((n >> pos) + i).separate_with_underscores(), num); + if round((n >> pos) + i) == num { + println!("Adding {}, the source of {}", i, num); n += i << pos; continue 'numloop; } } println!("Not Possible to find equivalent of {}", num); } - println!("Testing {}", n); + println!("Testing {}", format!("{:018b}", n).separate_with_dots()); + if n >= 48331947862051 { + println!("Failed"); + return; + } + mem.reset(); mem.a = n; - mem.b = 0; - mem.c = 0; - mem.pos = 0; - mem.output.clear(); mem.generic_process(); if mem.output == mem.ops { println!("A: {n}") diff --git a/examples/2024/17.txt b/examples/2024/17.txt new file mode 100644 index 0000000..4a91c26 --- /dev/null +++ b/examples/2024/17.txt @@ -0,0 +1,5 @@ +Register A: 2024 +Register B: 0 +Register C: 0 + +Program: 0,3,5,4,3,0