From 2fdcf171b0eb12bf5e6d9a72184172b847305632 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Tue, 14 Dec 2021 22:08:36 -0800 Subject: [PATCH] Day 13 part 2 --- 2021/src/day13.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/2021/src/day13.rs b/2021/src/day13.rs index b025e0f..3eda843 100644 --- a/2021/src/day13.rs +++ b/2021/src/day13.rs @@ -148,13 +148,35 @@ fn part1(input: &str) -> Result { Ok(im.count()) } -/* #[aoc(day13, part2)] fn part2(input: &str) -> Result { -todo!("part2"); -Ok(0) + let (pts, folds) = input.split_once("\n\n").unwrap(); + let pts: Vec<(usize, usize)> = pts + .lines() + .map(|l| l.split_once(',').unwrap()) + .map(|(x, y)| (x.parse().unwrap(), y.parse().unwrap())) + .collect(); + let folds: Vec<_> = folds + .lines() + .map(|l| l.split(' ').nth(2).unwrap().split_once('=').unwrap()) + .map(|(axis, idx)| (axis, idx.parse().unwrap())) + .collect(); + let (maxx, maxy) = pts + .iter() + .fold((0, 0), |(maxx, maxy), (x, y)| (maxx.max(*x), maxy.max(*y))); + let mut im = Image::new_with_pts(maxx + 1, maxy + 1, &pts); + //dbg!(&im); + + for (axis, idx) in folds.iter() { + im = if *axis == "y" { + im.fold_y(*idx) + } else { + im.fold_x(*idx) + }; + } + dbg!(&im); + Ok(im.count()) } -*/ #[cfg(test)] mod tests {