[hs] Migrate 2019_01
This commit is contained in:
parent
55bc09948b
commit
3e82db1f0c
3 changed files with 22 additions and 9 deletions
|
|
@ -5,6 +5,7 @@ import Control.Monad
|
|||
import Options.Applicative
|
||||
|
||||
import Aoc.Day (Day (..), Year (..))
|
||||
import qualified Aoc.Y2019 as Y2019
|
||||
import qualified Aoc.Y2020 as Y2020
|
||||
|
||||
lpad :: a -> Int -> [a] -> [a]
|
||||
|
|
@ -28,7 +29,8 @@ dayToParser (DayFile f) = f <$> strArgument (metavar "INPUTFILE")
|
|||
|
||||
parser :: Parser (IO ())
|
||||
parser = yearsToParser
|
||||
[ Y2020.year
|
||||
[ Y2019.year
|
||||
, Y2020.year
|
||||
]
|
||||
|
||||
opts :: ParserInfo (IO ())
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
module Aoc.Y2019
|
||||
( days
|
||||
( year
|
||||
) where
|
||||
|
||||
import Aoc.Day
|
||||
import qualified Aoc.Y2019.D01 as D01
|
||||
|
||||
days :: [Day]
|
||||
days = []
|
||||
year :: Year
|
||||
year = Year 2019
|
||||
[ ( 1, D01.day)
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,21 +1,29 @@
|
|||
module Aoc.Y2019.A01
|
||||
( solve201901
|
||||
module Aoc.Y2019.D01
|
||||
( day
|
||||
) where
|
||||
|
||||
import Aoc.Day
|
||||
import Aoc.Parse
|
||||
|
||||
fuel :: Integer -> Integer
|
||||
fuel n = (n `div` 3) - 2
|
||||
|
||||
iteratedFuel :: Integer -> Integer
|
||||
iteratedFuel = sum . takeWhile (> 0) . tail . iterate fuel
|
||||
|
||||
solve201901 :: FilePath -> IO ()
|
||||
solve201901 f = do
|
||||
values <- map read . lines <$> readFile f
|
||||
parser :: Parser [Integer]
|
||||
parser = manyLines decimal
|
||||
|
||||
solver :: [Integer] -> IO ()
|
||||
solver values = do
|
||||
putStrLn ">> Part 1"
|
||||
putStr "Total fuel: "
|
||||
print $ sum $ map fuel values
|
||||
|
||||
putStrLn ""
|
||||
putStrLn ">> Part 2"
|
||||
putStr "Total fuel (iterated): "
|
||||
print $ sum $ map iteratedFuel values
|
||||
|
||||
day :: Day
|
||||
day = dayParse parser solver
|
||||
Loading…
Add table
Add a link
Reference in a new issue