From c4a5d93f6ce7c9c6579e9fa993f72289b715f13e Mon Sep 17 00:00:00 2001 From: erius Date: Tue, 5 Dec 2023 16:59:33 +0300 Subject: [PATCH] Simplified day 3 part 1 solution --- src/bin/day3.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/bin/day3.rs b/src/bin/day3.rs index ab62883..dcb2d89 100644 --- a/src/bin/day3.rs +++ b/src/bin/day3.rs @@ -17,13 +17,11 @@ fn adjacent_numbers(lines: &Vec<&str>, line_index: usize, char_index: usize) -> let char_offsetted_index = (char_index as i32 + dx) as usize; let c = line.as_bytes()[char_offsetted_index] as char; if !c.is_digit(10) { continue; } + let prev_c = line.as_bytes()[char_offsetted_index - 1] as char; + if dx != -1 && prev_c.is_digit(10) { continue; } let number = find_full_number(line, char_offsetted_index, c); numbers.push(number); } - let row_left = &line[char_index - 1..=char_index]; - if row_left.chars().filter(|c| c .is_digit(10)).count() == 2 { numbers.pop(); } - let row_right = &line[char_index..=char_index + 1]; - if row_right.chars().filter(|c| c.is_digit(10)).count() == 2 { numbers.pop(); } } numbers }