Simplified day 3 part 1 solution
This commit is contained in:
parent
d0f307bc02
commit
c4a5d93f6c
1 changed files with 2 additions and 4 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue