Some small updates
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Julius 2021-12-14 09:06:01 +01:00
parent ce13c17b1e
commit 7710d82945
Signed by: j00lz
GPG key ID: AF241B0AA237BBA2

View file

@ -43,11 +43,11 @@ impl Day for Day13 {
fn part1(&self) -> anyhow::Result<String> {
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<String> {
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)));