2020: day10: use windows for part 1
This commit is contained in:
parent
2381f61118
commit
e2544f5160
|
@ -39,7 +39,9 @@ fn part1(input: &str) -> aoc::Result<usize> {
|
||||||
|
|
||||||
let mut differences: [usize; 4] = [0; 4];
|
let mut differences: [usize; 4] = [0; 4];
|
||||||
|
|
||||||
for (prev, next) in jolts.iter().zip(jolts.iter().skip(1)) {
|
for window in jolts.windows(2) {
|
||||||
|
let prev = window[0];
|
||||||
|
let next = window[1];
|
||||||
let difference = (next - prev) as usize;
|
let difference = (next - prev) as usize;
|
||||||
differences[difference] += 1;
|
differences[difference] += 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue