Found the inefficiency. Could probably write this better, but happy with the performance now
This commit is contained in:
491
day_10/flamegraph.svg
Normal file
491
day_10/flamegraph.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 1.3 MiB |
BIN
day_10/perf.data
Normal file
BIN
day_10/perf.data
Normal file
Binary file not shown.
BIN
day_10/perf.data.old
Normal file
BIN
day_10/perf.data.old
Normal file
Binary file not shown.
@@ -147,7 +147,7 @@ pub fn part2(input: &str) -> String {
|
||||
// L's cancel F's, J's cancel 7's
|
||||
if count_map[[new_y,x]] != 0 {
|
||||
// We can add either a half or full count
|
||||
let next_character = input.lines().nth(new_y).unwrap().chars().nth(x).unwrap();
|
||||
let next_character = std::str::from_utf8(&[input.as_bytes()[new_y*columns + x]]).unwrap().chars().next().unwrap();
|
||||
if ['7', 'S'].contains(&next_character) {
|
||||
count_7 += 1;
|
||||
} else if next_character == 'J' {
|
||||
@@ -161,9 +161,7 @@ pub fn part2(input: &str) -> String {
|
||||
}
|
||||
}
|
||||
}
|
||||
count_f = count_f.abs();
|
||||
count_7 = count_7.abs();
|
||||
sum += (count_f + count_7) as f32 / 2.0;
|
||||
sum += (count_f.abs() + count_7.abs()) as f32 / 2.0;
|
||||
if sum % 2.0 != 0.0 {
|
||||
inside_points += 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user