diff --git a/app/10.hs b/app/10.hs index 20a7fba..1bdc35e 100644 --- a/app/10.hs +++ b/app/10.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE LambdaCase #-} module Main where import Data.Functor @@ -21,12 +20,17 @@ travel :: (Int,Int) -> Matrix Int -> [(Int,Int)] travel p s = let curr = uncurry getElem p s in if curr == 9 then [p] else getAbove p s >>= (`travel` s) -solve1 :: Matrix Int -> Int -solve1 s = length . concatMap (nub . (`travel` s)) $ getAllDigit 0 s +travel' :: (Int,Int) -> Matrix Int -> Int +travel' p s = let curr = uncurry getElem p s in + if curr == 9 then 1 else sum $ getAbove p s <&> (`travel'` s) -solve2 = undefined +solve1 :: Matrix Int -> Int +solve1 s = length $ nub . (`travel` s) =<< getAllDigit 0 s + +solve2 :: Matrix Int -> Int +solve2 s = sum $ getAllDigit 0 s <&> (`travel'` s) main :: IO () main = readFile "inputs/10" <&> parse >>= \i -> - print (solve1 i) - -- >> print (solve2 i) + print (solve1 i) >> + print (solve2 i)