From 7710d829454a18c766ddc46e7a8f8de3c789e6f9 Mon Sep 17 00:00:00 2001 From: Julius de Jeu Date: Tue, 14 Dec 2021 09:06:01 +0100 Subject: [PATCH] Some small updates --- src/day13.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/day13.rs b/src/day13.rs index 62c540b..02ed8dc 100644 --- a/src/day13.rs +++ b/src/day13.rs @@ -43,11 +43,11 @@ impl Day for Day13 { fn part1(&self) -> anyhow::Result { let fold = self.folds[0]; let map = self.points.clone(); - Ok(format!("{}", flip(map, fold).len())) + Ok(format!("{}", flip(map, &fold).len())) } fn part2(&self) -> anyhow::Result { - let r = self.folds.iter().fold(self.points.clone(), |a, &b| flip(a, b)); + let r = self.folds.iter().fold(self.points.clone(), flip); let max_x = r.iter().max_by(|&(xm, _), &(xn, _)| xm.cmp(xn)).ok_or_else(|| anyhow::Error::msg("X is empty!"))?; let max_y = r.iter().max_by(|&(_, xm), &(_, xn)| xm.cmp(xn)).ok_or_else(|| anyhow::Error::msg("Y is empty!"))?; let mut z = String::new(); @@ -65,8 +65,8 @@ impl Day for Day13 { } } -fn flip(set: HashSet<(i32, i32)>, f: Fold) -> HashSet<(i32, i32)> { - set.iter().map(|&e| flip_one(e, f)).collect() +fn flip(set: HashSet<(i32, i32)>, f: &Fold) -> HashSet<(i32, i32)> { + set.iter().map(|&e| flip_one(e, *f)).collect() } fn flip_one((x, y): (i32, i32), f: Fold) -> (i32, i32) { @@ -128,7 +128,7 @@ fold along x=5"; #[test] fn flip_set_test() { let set = HashSet::from([(0, 3), (3, 2), (6, 3)]); - let r = flip(set, Fold::X(3)); + let r = flip(set, &Fold::X(3)); assert!(r.contains(&(0, 3))); assert!(r.contains(&(3, 2))); assert!(!r.contains(&(6, 3)));