Bugfix for 2023 day 03: Handle number in very last position correctly
This commit is contained in:
parent
e0f463a14a
commit
7f5d8635cc
2 changed files with 10 additions and 5 deletions
|
@ -16,7 +16,7 @@ fn find_part_numbers(input: &str) -> (Vec<usize>, Vec<usize>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut cur_num = 0;
|
let mut cur_num = 0;
|
||||||
for (line_idx, line) in input.lines().enumerate() {
|
for (line_idx, line) in input.lines().chain("\n".lines()).enumerate() {
|
||||||
if cur_num > 0 {
|
if cur_num > 0 {
|
||||||
let digits = (1_u32..).find(|d| 10_usize.pow(*d) > cur_num).unwrap() as usize;
|
let digits = (1_u32..).find(|d| 10_usize.pow(*d) > cur_num).unwrap() as usize;
|
||||||
let mut is_part = false;
|
let mut is_part = false;
|
||||||
|
@ -89,10 +89,15 @@ mod tests {
|
||||||
read_to_string(name).expect(&format!("Unable to read file: {name}")[..]).trim().to_string()
|
read_to_string(name).expect(&format!("Unable to read file: {name}")[..]).trim().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty_str() {
|
||||||
|
assert_eq!(run(""), (0, 0))
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_sample() {
|
fn test_sample() {
|
||||||
let sample_input = read_file("tests/sample_input");
|
let sample_input = read_file("tests/sample_input");
|
||||||
assert_eq!(run(&sample_input), (4361, 467835));
|
assert_eq!(run(&sample_input), (4364, 467835));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -5,6 +5,6 @@
|
||||||
617*......
|
617*......
|
||||||
.....+.58.
|
.....+.58.
|
||||||
..592.....
|
..592.....
|
||||||
......755.
|
......755.1
|
||||||
...$.*....
|
...$.*...*
|
||||||
.664.598..
|
.664.598.2
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue