Solve day 1

This commit is contained in:
George Thomas 2025-12-02 01:37:59 +00:00
parent 5db06f95a7
commit 14361a0440
5 changed files with 56 additions and 2 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "inputs/real"]
path = inputs/real
url = git@github.com:georgefst/aoc-private-inputs.git

View File

@ -9,6 +9,10 @@ executable aoc
main-is: Main.hs main-is: Main.hs
hs-source-dirs: app hs-source-dirs: app
default-language: GHC2024 default-language: GHC2024
default-extensions:
BlockArguments
MultiWayIf
ViewPatterns
ghc-options: ghc-options:
-Wall -Wall
build-depends: build-depends:

View File

@ -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 :: 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

10
inputs/examples/1 Normal file
View File

@ -0,0 +1,10 @@
L68
L30
R48
L5
R60
L55
L1
L99
R14
L82

1
inputs/real Submodule

@ -0,0 +1 @@
Subproject commit ab940388ba53f2fef932d09aeb44443e2a9407b7