Skip to content

Commit ee615cb

Browse files
committed
day 10 wip
1 parent acf2b3b commit ee615cb

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/Day10.hs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ rating :: Matrix Int -> Point -> Point -> Int
2222
rating matrix x y = go (getCandidates 1 x) [y] 1
2323
where
2424
go :: [Point] -> [Point] -> Int -> Int
25-
go _ _ 6 = 0
26-
go leftFront rightFront step =
27-
let leftFront' = concatMap (getCandidates (1 + step)) leftFront
28-
rightFront' = concatMap (getCandidates (9 - step)) rightFront
29-
intersection = intersect leftFront rightFront
30-
in if not (null intersection)
31-
then length intersection
32-
else go leftFront' rightFront' (step + 1)
25+
go leftFront rightFront step
26+
| step > 5 = 0
27+
| step < 5 =
28+
let leftFront' = concatMap (getCandidates (1 + step)) leftFront
29+
rightFront' = concatMap (getCandidates (9 - step)) rightFront
30+
in go leftFront' rightFront' (step + 1)
31+
| otherwise =
32+
let intersectionA = intersect leftFront rightFront
33+
intersectionB = intersect rightFront leftFront
34+
intersection = if length intersectionA > length intersectionB then intersectionA else intersectionB
35+
in length intersection
3336

3437
getCandidates :: Int -> Point -> [Point]
3538
getCandidates value (row, col) =

0 commit comments

Comments
 (0)