Misc fixes

This commit is contained in:
2023-12-13 18:41:15 +01:00
parent 0c4430ad01
commit 975a1f8faf
2 changed files with 3 additions and 3 deletions

View File

@@ -32,7 +32,7 @@ fn compute_next<'a>(report: impl IntoIterator<Item = &'a i32>, deltas: &mut Vec<
let mut delta = entry; let mut delta = entry;
for prev_delta in &mut *deltas { for prev_delta in &mut *deltas {
let prev = mem::replace(prev_delta, delta); let prev = mem::replace(prev_delta, delta);
delta = delta - prev; delta -= prev;
} }
if delta != 0 { if delta != 0 {
@@ -40,7 +40,7 @@ fn compute_next<'a>(report: impl IntoIterator<Item = &'a i32>, deltas: &mut Vec<
} }
} }
deltas.iter().rev().fold(0, |c, d| c + d) deltas.iter().rev().sum::<i32>()
} }
pub fn part1(input: &[u8]) -> anyhow::Result<String> { pub fn part1(input: &[u8]) -> anyhow::Result<String> {

View File

@@ -69,7 +69,7 @@ pub fn part1(input: &[u8]) -> anyhow::Result<String> {
let total: u64 = lines let total: u64 = lines
.iter() .iter()
.map(|(line, groups)| number_ways(*line, groups)) .map(|(line, groups)| number_ways(line, groups))
.sum(); .sum();
Ok(total.to_string()) Ok(total.to_string())