From ee615cb0c4eca7c2ea0f75f31cc36596abc9514c Mon Sep 17 00:00:00 2001 From: JasterV <49537445+JasterV@users.noreply.github.com> Date: Tue, 1 Apr 2025 23:56:45 +0200 Subject: [PATCH] day 10 wip --- src/Day10.hs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Day10.hs b/src/Day10.hs index a682021..7fbbdc4 100644 --- a/src/Day10.hs +++ b/src/Day10.hs @@ -22,14 +22,17 @@ rating :: Matrix Int -> Point -> Point -> Int rating matrix x y = go (getCandidates 1 x) [y] 1 where go :: [Point] -> [Point] -> Int -> Int - go _ _ 6 = 0 - go leftFront rightFront step = - let leftFront' = concatMap (getCandidates (1 + step)) leftFront - rightFront' = concatMap (getCandidates (9 - step)) rightFront - intersection = intersect leftFront rightFront - in if not (null intersection) - then length intersection - else go leftFront' rightFront' (step + 1) + go leftFront rightFront step + | step > 5 = 0 + | step < 5 = + let leftFront' = concatMap (getCandidates (1 + step)) leftFront + rightFront' = concatMap (getCandidates (9 - step)) rightFront + in go leftFront' rightFront' (step + 1) + | otherwise = + let intersectionA = intersect leftFront rightFront + intersectionB = intersect rightFront leftFront + intersection = if length intersectionA > length intersectionB then intersectionA else intersectionB + in length intersection getCandidates :: Int -> Point -> [Point] getCandidates value (row, col) =