[hs] Switch to new day system
This commit is contained in:
parent
3b0ea44036
commit
b87c8e4555
4 changed files with 35 additions and 39 deletions
|
|
@ -1,34 +1,24 @@
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
|
import Control.Monad
|
||||||
|
|
||||||
import Options.Applicative
|
import Options.Applicative
|
||||||
|
|
||||||
import Aoc.Y2019
|
import Aoc.Day (Day (..))
|
||||||
import Aoc.Y2020
|
import qualified Aoc.Y2019 as Y2019
|
||||||
|
import qualified Aoc.Y2020 as Y2020
|
||||||
|
|
||||||
data Settings = Settings
|
toCommand :: Day -> Mod CommandFields (IO ())
|
||||||
{ function :: FilePath -> IO ()
|
toCommand (DayPure name f) = command name $ info (helper <*> pure f) mempty
|
||||||
, filename :: FilePath
|
toCommand (DayFile name f) = command name $ info (helper <*> p) mempty
|
||||||
}
|
where
|
||||||
|
p = f <$> strArgument (metavar "INPUTFILE")
|
||||||
|
|
||||||
solutions :: Parser (FilePath -> IO ())
|
parser :: Parser (IO ())
|
||||||
solutions = subparser $ mconcat $ map (\(name, func) -> command name (info (pure func) mempty))
|
parser = subparser $ mconcat $ map toCommand $ Y2019.days ++ Y2020.days
|
||||||
[ ("2019_01", solve201901)
|
|
||||||
, ("2019_02", solve201902)
|
|
||||||
, ("2019_03", solve201903)
|
|
||||||
, ("2019_04", solve201904)
|
|
||||||
, ("2019_05", solve201905)
|
|
||||||
, ("2020_01", solve202001)
|
|
||||||
]
|
|
||||||
|
|
||||||
parser :: Parser Settings
|
opts :: ParserInfo (IO ())
|
||||||
parser = Settings
|
|
||||||
<$> solutions
|
|
||||||
<*> strArgument (metavar "INPUTFILE")
|
|
||||||
|
|
||||||
opts :: ParserInfo Settings
|
|
||||||
opts = info (helper <*> parser) $ fullDesc <> failureCode 1
|
opts = info (helper <*> parser) $ fullDesc <> failureCode 1
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = join $ customExecParser (prefs showHelpOnEmpty) opts
|
||||||
settings <- customExecParser (prefs showHelpOnEmpty) opts
|
|
||||||
function settings $ filename settings
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,8 @@
|
||||||
module Aoc.Y2019
|
module Aoc.Y2019
|
||||||
( solve201901
|
( days
|
||||||
, solve201902
|
|
||||||
, solve201903
|
|
||||||
, solve201904
|
|
||||||
, solve201905
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Aoc.Y2019.A01
|
import Aoc.Day
|
||||||
import Aoc.Y2019.A02
|
|
||||||
import Aoc.Y2019.A03
|
days :: [Day]
|
||||||
import Aoc.Y2019.A04
|
days = []
|
||||||
import Aoc.Y2019.A05
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
module Aoc.Y2020
|
module Aoc.Y2020
|
||||||
( solve202001
|
( days
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Aoc.Y2020.A01
|
import Aoc.Day
|
||||||
|
import qualified Aoc.Y2020.D01 as D01
|
||||||
|
|
||||||
|
days :: [Day]
|
||||||
|
days =
|
||||||
|
[ D01.day
|
||||||
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
module Aoc.Y2020.A01
|
module Aoc.Y2020.D01
|
||||||
( solve202001
|
( day
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
|
|
||||||
|
import Aoc.Day
|
||||||
|
|
||||||
findPair :: [Integer] -> (Integer, Integer)
|
findPair :: [Integer] -> (Integer, Integer)
|
||||||
findPair l = head $ do
|
findPair l = head $ do
|
||||||
a <- l
|
a <- l
|
||||||
|
|
@ -30,3 +32,6 @@ solve202001 f = do
|
||||||
let (y1, y2, y3) = findTriple values
|
let (y1, y2, y3) = findTriple values
|
||||||
putStrLn ">> Part 2"
|
putStrLn ">> Part 2"
|
||||||
putStrLn $ show y1 ++ " * " ++ show y2 ++ " * " ++ show y3 ++ " = " ++ show (y1 * y2 * y3)
|
putStrLn $ show y1 ++ " * " ++ show y2 ++ " * " ++ show y3 ++ " = " ++ show (y1 * y2 * y3)
|
||||||
|
|
||||||
|
day :: Day
|
||||||
|
day = dayFile "2020_01" solve202001
|
||||||
Loading…
Add table
Add a link
Reference in a new issue