Part 1 done
This commit is contained in:
parent
27e4f9102b
commit
fb98633a56
@ -102,6 +102,7 @@ executable 9
|
|||||||
-- other-extensions:
|
-- other-extensions:
|
||||||
build-depends: base ^>=4.18.2.1
|
build-depends: base ^>=4.18.2.1
|
||||||
, split
|
, split
|
||||||
|
, extra
|
||||||
hs-source-dirs: app
|
hs-source-dirs: app
|
||||||
default-language: GHC2021
|
default-language: GHC2021
|
||||||
executable 10
|
executable 10
|
||||||
|
34
app/9.hs
34
app/9.hs
@ -2,14 +2,36 @@
|
|||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import Data.Functor
|
import Data.Functor
|
||||||
|
import Data.List
|
||||||
|
import Data.List.Extra
|
||||||
|
|
||||||
parse = undefined
|
data ℜ where
|
||||||
|
None :: ℜ
|
||||||
|
Num :: Int -> ℜ
|
||||||
|
deriving Eq
|
||||||
|
|
||||||
solve1 = undefined
|
instance Show ℜ where
|
||||||
|
show None = show '.'
|
||||||
|
show (Num n) = show n
|
||||||
|
|
||||||
solve2 = undefined
|
parse :: String -> [ℜ]
|
||||||
|
parse s = zip [0..] (trim s) >>= \(i,a) -> replicate (read [a]) (if even i then Num (i `div` 2) else None)
|
||||||
|
|
||||||
|
sort1 :: [ℜ] -> [ℜ]
|
||||||
|
sort1 s
|
||||||
|
| None `notElem` s = s
|
||||||
|
| otherwise = case last s of
|
||||||
|
None -> sort1 $ init s
|
||||||
|
n -> sort1 $ takeWhile (/= None) s ++ [n] ++ drop 1 (dropWhile (/= None) (init s))
|
||||||
|
|
||||||
|
sort2 :: [ℜ] -> [ℜ]
|
||||||
|
sort2 = undefined
|
||||||
|
|
||||||
|
solve :: ([ℜ] -> [ℜ]) -> [ℜ] -> Int
|
||||||
|
solve f s = let fixed = (\(Num n) -> n) <$> f s in
|
||||||
|
sum $ zipWith (*) fixed [0..]
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = readFile "inputs/9" <&> parse >>= \i ->
|
main = readFile "inputs/9.example" <&> parse >>= \i ->
|
||||||
print (solve1 i) >>
|
print (solve sort1 i) >>
|
||||||
print (solve2 i)
|
print (solve sort2 i)
|
||||||
|
Loading…
Reference in New Issue
Block a user