2020: day10: use windows for part 1

This commit is contained in:
Antoine Martin 2020-12-10 15:16:41 +01:00
parent 2381f61118
commit e2544f5160

View file

@ -39,7 +39,9 @@ fn part1(input: &str) -> aoc::Result<usize> {
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;
differences[difference] += 1;
}