diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4cfdeb1 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "inputs/real"] + path = inputs/real + url = git@github.com:georgefst/aoc-private-inputs.git diff --git a/aoc.cabal b/aoc.cabal index 01b732e..806cec6 100644 --- a/aoc.cabal +++ b/aoc.cabal @@ -9,6 +9,10 @@ executable aoc main-is: Main.hs hs-source-dirs: app default-language: GHC2024 + default-extensions: + BlockArguments + MultiWayIf + ViewPatterns ghc-options: -Wall build-depends: diff --git a/app/Main.hs b/app/Main.hs index 65ae4a0..fdae8b8 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,4 +1,40 @@ -module Main where +module Main (main) where + +import Control.Monad.State +import Data.Traversable +import Text.Read (readMaybe) main :: IO () -main = putStrLn "Hello, Haskell!" +main = do + Just input <- + traverse + ( \case + 'L' : (readMaybe -> Just i) -> Just (L, Inc i) + 'R' : (readMaybe -> Just i) -> Just (R, Inc i) + _ -> Nothing + ) + . lines + <$> readFile "inputs/examples/1" + print + . sum + . flip evalState 50 + $ for input \(d, i) -> state \p -> + let p' = step i d p + in (Count if p' == 0 then 1 else 0, p') + +data Direction = L | R + deriving (Eq, Ord, Show) + +newtype Pos = Pos Int + deriving newtype (Eq, Ord, Show, Num) + +newtype Inc = Inc Int + deriving newtype (Eq, Ord, Show, Num) + +newtype Count = Count Int + deriving newtype (Eq, Ord, Show, Num) + +step :: Inc -> Direction -> Pos -> Pos +step (Inc i) d (Pos p) = Pos case d of + L -> (p - i) `mod` 100 + R -> (p + i) `mod` 100 diff --git a/inputs/examples/1 b/inputs/examples/1 new file mode 100644 index 0000000..53287c7 --- /dev/null +++ b/inputs/examples/1 @@ -0,0 +1,10 @@ +L68 +L30 +R48 +L5 +R60 +L55 +L1 +L99 +R14 +L82 diff --git a/inputs/real b/inputs/real new file mode 160000 index 0000000..ab94038 --- /dev/null +++ b/inputs/real @@ -0,0 +1 @@ +Subproject commit ab940388ba53f2fef932d09aeb44443e2a9407b7