diff --git a/hs/app/Main.hs b/hs/app/Main.hs index cdfac72..de42bb1 100644 --- a/hs/app/Main.hs +++ b/hs/app/Main.hs @@ -1,34 +1,24 @@ module Main where -import Options.Applicative +import Control.Monad -import Aoc.Y2019 -import Aoc.Y2020 +import Options.Applicative -data Settings = Settings - { function :: FilePath -> IO () - , filename :: FilePath - } +import Aoc.Day (Day (..)) +import qualified Aoc.Y2019 as Y2019 +import qualified Aoc.Y2020 as Y2020 -solutions :: Parser (FilePath -> IO ()) -solutions = subparser $ mconcat $ map (\(name, func) -> command name (info (pure func) mempty)) - [ ("2019_01", solve201901) - , ("2019_02", solve201902) - , ("2019_03", solve201903) - , ("2019_04", solve201904) - , ("2019_05", solve201905) - , ("2020_01", solve202001) - ] +toCommand :: Day -> Mod CommandFields (IO ()) +toCommand (DayPure name f) = command name $ info (helper <*> pure f) mempty +toCommand (DayFile name f) = command name $ info (helper <*> p) mempty + where + p = f <$> strArgument (metavar "INPUTFILE") -parser :: Parser Settings -parser = Settings - <$> solutions - <*> strArgument (metavar "INPUTFILE") +parser :: Parser (IO ()) +parser = subparser $ mconcat $ map toCommand $ Y2019.days ++ Y2020.days -opts :: ParserInfo Settings +opts :: ParserInfo (IO ()) opts = info (helper <*> parser) $ fullDesc <> failureCode 1 main :: IO () -main = do - settings <- customExecParser (prefs showHelpOnEmpty) opts - function settings $ filename settings +main = join $ customExecParser (prefs showHelpOnEmpty) opts diff --git a/hs/src/Aoc/Y2019.hs b/hs/src/Aoc/Y2019.hs index 4f980b4..255d7e0 100644 --- a/hs/src/Aoc/Y2019.hs +++ b/hs/src/Aoc/Y2019.hs @@ -1,13 +1,8 @@ module Aoc.Y2019 - ( solve201901 - , solve201902 - , solve201903 - , solve201904 - , solve201905 + ( days ) where -import Aoc.Y2019.A01 -import Aoc.Y2019.A02 -import Aoc.Y2019.A03 -import Aoc.Y2019.A04 -import Aoc.Y2019.A05 +import Aoc.Day + +days :: [Day] +days = [] diff --git a/hs/src/Aoc/Y2020.hs b/hs/src/Aoc/Y2020.hs index 1438bc6..c1513e4 100644 --- a/hs/src/Aoc/Y2020.hs +++ b/hs/src/Aoc/Y2020.hs @@ -1,5 +1,11 @@ module Aoc.Y2020 - ( solve202001 + ( days ) where -import Aoc.Y2020.A01 +import Aoc.Day +import qualified Aoc.Y2020.D01 as D01 + +days :: [Day] +days = + [ D01.day + ] diff --git a/hs/src/Aoc/Y2020/A01.hs b/hs/src/Aoc/Y2020/D01.hs similarity index 83% rename from hs/src/Aoc/Y2020/A01.hs rename to hs/src/Aoc/Y2020/D01.hs index f689ca3..16e5bde 100644 --- a/hs/src/Aoc/Y2020/A01.hs +++ b/hs/src/Aoc/Y2020/D01.hs @@ -1,8 +1,10 @@ -module Aoc.Y2020.A01 - ( solve202001 +module Aoc.Y2020.D01 + ( day ) where -import Control.Monad +import Control.Monad + +import Aoc.Day findPair :: [Integer] -> (Integer, Integer) findPair l = head $ do @@ -30,3 +32,6 @@ solve202001 f = do let (y1, y2, y3) = findTriple values putStrLn ">> Part 2" putStrLn $ show y1 ++ " * " ++ show y2 ++ " * " ++ show y3 ++ " = " ++ show (y1 * y2 * y3) + +day :: Day +day = dayFile "2020_01" solve202001