mirror of
https://codeberg.org/JasterV/aoc2024-haskell.git
synced 2026-04-26 18:10:05 +00:00
day 10 wip
This commit is contained in:
parent
acf2b3b964
commit
ee615cb0c4
1 changed files with 11 additions and 8 deletions
19
src/Day10.hs
19
src/Day10.hs
|
|
@ -22,14 +22,17 @@ rating :: Matrix Int -> Point -> Point -> Int
|
||||||
rating matrix x y = go (getCandidates 1 x) [y] 1
|
rating matrix x y = go (getCandidates 1 x) [y] 1
|
||||||
where
|
where
|
||||||
go :: [Point] -> [Point] -> Int -> Int
|
go :: [Point] -> [Point] -> Int -> Int
|
||||||
go _ _ 6 = 0
|
go leftFront rightFront step
|
||||||
go leftFront rightFront step =
|
| step > 5 = 0
|
||||||
let leftFront' = concatMap (getCandidates (1 + step)) leftFront
|
| step < 5 =
|
||||||
rightFront' = concatMap (getCandidates (9 - step)) rightFront
|
let leftFront' = concatMap (getCandidates (1 + step)) leftFront
|
||||||
intersection = intersect leftFront rightFront
|
rightFront' = concatMap (getCandidates (9 - step)) rightFront
|
||||||
in if not (null intersection)
|
in go leftFront' rightFront' (step + 1)
|
||||||
then length intersection
|
| otherwise =
|
||||||
else go leftFront' rightFront' (step + 1)
|
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 :: Int -> Point -> [Point]
|
||||||
getCandidates value (row, col) =
|
getCandidates value (row, col) =
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue