Simplified day 3 part 1 solution

This commit is contained in:
Egor 2023-12-05 16:59:33 +03:00
parent d0f307bc02
commit c4a5d93f6c

View file

@ -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
}