Re-add first solution from temporary aoc repo
This commit is contained in:
parent
acf0e97b86
commit
c0c9e1c623
4 changed files with 44 additions and 8 deletions
|
|
@ -1,6 +1,28 @@
|
|||
module Main where
|
||||
|
||||
import Lib
|
||||
import Options.Applicative
|
||||
|
||||
import Aoc.Y2019.A01
|
||||
|
||||
data Settings = Settings
|
||||
{ function :: FilePath -> IO ()
|
||||
, filename :: FilePath
|
||||
}
|
||||
|
||||
solutions :: Parser (FilePath -> IO ())
|
||||
solutions = subparser $ mconcat $ map (\(name, func) -> command name (info (pure func) mempty))
|
||||
[ ("201901", solve201901)
|
||||
]
|
||||
|
||||
parser :: Parser Settings
|
||||
parser = Settings
|
||||
<$> solutions
|
||||
<*> strArgument (metavar "INPUTFILE")
|
||||
|
||||
opts :: ParserInfo Settings
|
||||
opts = info (helper <*> parser) $ fullDesc <> failureCode 1
|
||||
|
||||
main :: IO ()
|
||||
main = someFunc
|
||||
main = do
|
||||
settings <- execParser opts
|
||||
function settings $ filename settings
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ description: Please see the README on GitHub at <https://github.com/gith
|
|||
|
||||
dependencies:
|
||||
- base >= 4.7 && < 5
|
||||
- optparse-applicative
|
||||
|
||||
library:
|
||||
source-dirs: src
|
||||
|
|
|
|||
19
hs/src/Aoc/Y2019/A01.hs
Normal file
19
hs/src/Aoc/Y2019/A01.hs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
module Aoc.Y2019.A01
|
||||
( solve201901
|
||||
) where
|
||||
|
||||
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
|
||||
|
||||
putStr "Total fuel: "
|
||||
print $ sum $ map fuel values
|
||||
|
||||
putStr "Total fuel (iterated): "
|
||||
print $ sum $ map iteratedFuel values
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
module Lib
|
||||
( someFunc
|
||||
) where
|
||||
|
||||
someFunc :: IO ()
|
||||
someFunc = putStrLn "someFunc"
|
||||
Loading…
Add table
Add a link
Reference in a new issue