From d86f7b2ab3841f3f56743c0505a5a40d369c8aee Mon Sep 17 00:00:00 2001 From: Rh4096 Date: Thu, 5 Dec 2024 07:26:22 +0700 Subject: [PATCH] day 4.1 --- src/solutions/day_4.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/solutions/day_4.rs b/src/solutions/day_4.rs index d973ee5..44a4f86 100644 --- a/src/solutions/day_4.rs +++ b/src/solutions/day_4.rs @@ -80,11 +80,12 @@ impl AocSolution for AocDayFourSolution { let xmas = XmasGrid::new(Self::INPUT); let mut tmp = 0; - for (&pos, &ch) in &xmas.grid { - if ch == 'X' { - tmp += xmas.find_xmas(pos) - } - } + xmas.grid + .iter() + .filter(|(_, &ch)| ch == 'X') + .for_each(|(&pt, _)| { + tmp += xmas.find_xmas(pt); + }); tmp as Self::Output } @@ -93,11 +94,12 @@ impl AocSolution for AocDayFourSolution { let xmas = XmasGrid::new(Self::INPUT); let mut tmp = 0; - for (&pos, &ch) in &xmas.grid { - if ch == 'A' { - tmp += xmas.find_x_mas(pos) - } - } + xmas.grid + .iter() + .filter(|(_, &ch)| ch == 'A') + .for_each(|(&pt, _)| { + tmp += xmas.find_x_mas(pt); + }); tmp as Self::Output }