Part 2 easy
This commit is contained in:
parent
9b187ca14b
commit
5796436650
16
app/10.hs
16
app/10.hs
@ -1,4 +1,3 @@
|
|||||||
{-# LANGUAGE LambdaCase #-}
|
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import Data.Functor
|
import Data.Functor
|
||||||
@ -21,12 +20,17 @@ travel :: (Int,Int) -> Matrix Int -> [(Int,Int)]
|
|||||||
travel p s = let curr = uncurry getElem p s in
|
travel p s = let curr = uncurry getElem p s in
|
||||||
if curr == 9 then [p] else getAbove p s >>= (`travel` s)
|
if curr == 9 then [p] else getAbove p s >>= (`travel` s)
|
||||||
|
|
||||||
solve1 :: Matrix Int -> Int
|
travel' :: (Int,Int) -> Matrix Int -> Int
|
||||||
solve1 s = length . concatMap (nub . (`travel` s)) $ getAllDigit 0 s
|
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 :: IO ()
|
||||||
main = readFile "inputs/10" <&> parse >>= \i ->
|
main = readFile "inputs/10" <&> parse >>= \i ->
|
||||||
print (solve1 i)
|
print (solve1 i) >>
|
||||||
-- >> print (solve2 i)
|
print (solve2 i)
|
||||||
|
Loading…
Reference in New Issue
Block a user