Initial commit
This commit is contained in:
commit
cf2af11b6b
23 changed files with 3988 additions and 0 deletions
28
src/AoC.hs
Normal file
28
src/AoC.hs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module AoC (
|
||||
defaultMain,
|
||||
) where
|
||||
|
||||
import AoC.Day
|
||||
import AoC.Riddle
|
||||
import AoC.Year
|
||||
|
||||
import Control.Exception qualified as Exception
|
||||
import System.IO (hPutStrLn)
|
||||
import System.IO.Error qualified as IOError
|
||||
|
||||
-- import AoC.Y0000 qualified as Y0000
|
||||
|
||||
runAoC :: [String] -> IO ()
|
||||
runAoC _args =
|
||||
putStrLn "Hello"
|
||||
|
||||
handleError :: IOError.IOError -> IO ()
|
||||
handleError e = do
|
||||
hPutStrLn stderr $ "I ran into an issue: " <> show e
|
||||
|
||||
defaultMain :: IO ()
|
||||
defaultMain = do
|
||||
args <- getArgs
|
||||
Exception.catch (runAoC args) handleError
|
||||
29
src/AoC/Day.hs
Normal file
29
src/AoC/Day.hs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
module AoC.Day (Day (..)) where
|
||||
|
||||
data Day
|
||||
= D01
|
||||
| D02
|
||||
| D03
|
||||
| D04
|
||||
| D05
|
||||
| D06
|
||||
| D07
|
||||
| D08
|
||||
| D09
|
||||
| D10
|
||||
| D11
|
||||
| D12
|
||||
| D13
|
||||
| D14
|
||||
| D15
|
||||
| D16
|
||||
| D17
|
||||
| D18
|
||||
| D19
|
||||
| D20
|
||||
| D21
|
||||
| D22
|
||||
| D23
|
||||
| D24
|
||||
| D25
|
||||
deriving stock (Read, Show, Eq, Ord, Enum)
|
||||
20
src/AoC/Riddle.hs
Normal file
20
src/AoC/Riddle.hs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
module AoC.Riddle (
|
||||
Riddle (..),
|
||||
Error (..),
|
||||
Solution (..),
|
||||
loadRiddle,
|
||||
) where
|
||||
|
||||
import AoC.Util (readFileUtf8)
|
||||
|
||||
import AoC.Day
|
||||
import AoC.Year
|
||||
|
||||
type Riddle = Text
|
||||
type Error = Text
|
||||
type Solution = [Integer]
|
||||
|
||||
loadRiddle :: (MonadIO m) => Year -> Day -> m Riddle
|
||||
loadRiddle y d = readFileUtf8 inputFile
|
||||
where
|
||||
inputFile = intercalate "/" ["data", show y, show d, "riddle"]
|
||||
11
src/AoC/Util.hs
Normal file
11
src/AoC/Util.hs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
-- | Internal module in order to facilitate testability.
|
||||
module AoC.Util (solveRiddle, readFileUtf8) where
|
||||
|
||||
readFileUtf8 :: (MonadIO m) => FilePath -> m Text
|
||||
readFileUtf8 = fmap (decodeUtf8With lenientDecode) . readFileBS
|
||||
|
||||
solveRiddle :: (MonadIO m) => FilePath -> (Text -> [Text]) -> m ()
|
||||
solveRiddle file solver = do
|
||||
results <- solver <$> readFileUtf8 file
|
||||
forM_ (results `zip` [1 :: Int ..]) $ \(solution, part) ->
|
||||
putTextLn $ " solution to part-" <> show part <> ": " <> solution
|
||||
5
src/AoC/Year.hs
Normal file
5
src/AoC/Year.hs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
module AoC.Year (Year (..)) where
|
||||
|
||||
data Year
|
||||
= Y0000
|
||||
deriving stock (Read, Show, Eq, Ord, Enum)
|
||||
Loading…
Add table
Add a link
Reference in a new issue