From b9dc620b95927e0c4acd8d2b564ce1d0d5e8f224 Mon Sep 17 00:00:00 2001 From: Tabby <41929769+tabby-cat-nya@users.noreply.github.com> Date: Tue, 2 Dec 2025 10:56:18 +0000 Subject: [PATCH] part 1 solved --- aoc-2/src/main.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/aoc-2/src/main.rs b/aoc-2/src/main.rs index 1eea085..11a9c82 100644 --- a/aoc-2/src/main.rs +++ b/aoc-2/src/main.rs @@ -20,7 +20,7 @@ fn main() { let line = fs::read_to_string(file_path).unwrap(); println!("{line}"); - // let mut results = vec![]; + let mut invalids: Vec = Vec::new(); // parse the provided ranges into paits let ranges: Vec<(&str, &str)> = re.captures_iter(&line).map(|caps| { @@ -39,10 +39,30 @@ fn main() { while count <= end{ // if odd number of didgits, then no match, skip to next loop // if even number, then compare the first and second half + let current = count.to_string(); + + if current.len() % 2 != 1{ + let half_len = current.len()/2; + let half_a = ¤t[..half_len]; + let half_b = ¤t[half_len..]; + let current_str = current.to_string(); + println!("{current_str} = {half_a} + {half_b}"); + + if half_a == half_b{ + invalids.push(count); + } + } count += 1; } } + println!("{invalids:?}"); + let mut solution: i64 = 0; + for result in invalids{ + solution += result; + } + println!("Puzzle Solution: {solution}") + // Correct :3 }