Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcacheux committed Dec 9, 2023
1 parent a35d26f commit 7b76ba2
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/aoc2023/day9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,16 @@ fn solve(input: &Vec<Vec<i32>>, part2: bool) -> i32 {
current = next_line;
}

for i in (0..history.len()).rev() {
let under_value = if i + 1 < history.len() {
history[i + 1]
} else {
0
};

history[i] = if part2 {
history[i] - under_value
} else {
history[i] + under_value
};
}
sum += history[0];
sum += history.into_iter().rev().fold(
0,
|acc, value| {
if part2 {
value - acc
} else {
value + acc
}
},
);
}
sum
}

0 comments on commit 7b76ba2

Please sign in to comment.