better interface
This commit is contained in:
parent
26eca87c9e
commit
e92425f531
3 changed files with 47 additions and 1 deletions
|
@ -34,8 +34,8 @@ library
|
|||
Day4
|
||||
Day5
|
||||
Day6
|
||||
other-modules:
|
||||
Day7
|
||||
other-modules:
|
||||
Paths_adventofcode
|
||||
build-depends:
|
||||
base >=4.7 && <5
|
||||
|
@ -57,6 +57,7 @@ executable adventofcode-exe
|
|||
, adventofcode
|
||||
, protolude
|
||||
, pretty
|
||||
, containers
|
||||
default-language: Haskell2010
|
||||
|
||||
test-suite adventofcode-test
|
||||
|
|
43
app/Main.hs
43
app/Main.hs
|
@ -3,11 +3,16 @@
|
|||
module Main where
|
||||
|
||||
import Protolude
|
||||
|
||||
import Text.PrettyPrint hiding ((<>))
|
||||
import System.Environment (getArgs)
|
||||
import qualified Data.Map as Map
|
||||
|
||||
import qualified Day1
|
||||
import qualified Day2
|
||||
import qualified Day5
|
||||
import qualified Day6
|
||||
import qualified Day7
|
||||
|
||||
showSol :: [Char] -> Doc -> IO ()
|
||||
showSol txt d = putText . toS . render $
|
||||
|
@ -16,14 +21,43 @@ showSol txt d = putText . toS . render $
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
args <- getArgs
|
||||
fromMaybe (traverse_ snd (Map.toAscList solutions))
|
||||
(Map.lookup args solutions)
|
||||
|
||||
solutions :: Map [[Char]] (IO ())
|
||||
solutions = Map.fromList [(["1"], day1)
|
||||
,(["2"], day2)
|
||||
,(["5"], day5)
|
||||
,(["6"], day6)
|
||||
,(["7"], day7)
|
||||
]
|
||||
|
||||
day1 :: IO ()
|
||||
day1 = do
|
||||
putText "Day 1:"
|
||||
input1 <- Day1.ex1code
|
||||
showSol "Solution 1" (int (Day1.solution1 input1))
|
||||
showSol "Solution 2" (int (Day1.solution2 input1))
|
||||
|
||||
day2 :: IO ()
|
||||
day2 = do
|
||||
putText "Day 2:"
|
||||
input <- Day2.parseInput
|
||||
let sol1 = maybe 0 Day2.solution1 input
|
||||
showSol "Solution 1" (integer sol1)
|
||||
let sol2 = maybe 0 Day2.solution2 input
|
||||
showSol "Solution 2" (integer sol2)
|
||||
|
||||
day5 :: IO ()
|
||||
day5 = do
|
||||
putText "Day 5:"
|
||||
input5 <- Day5.parseInput
|
||||
sol5 <- Day5.solution2 input5
|
||||
showSol "Solution 2" (int sol5)
|
||||
|
||||
day6 :: IO ()
|
||||
day6 = do
|
||||
putText "Day 6:"
|
||||
input6_1 <- Day6.parseInput
|
||||
sol6_1 <- Day6.solution1 input6_1
|
||||
|
@ -31,3 +65,12 @@ main = do
|
|||
input6_2 <- Day6.parseInput
|
||||
sol6_2 <- Day6.solution2 input6_2
|
||||
showSol "Solution 2" (int sol6_2)
|
||||
|
||||
day7 :: IO ()
|
||||
day7 = do
|
||||
putText "Day 7:"
|
||||
input <- Day7.parseInput
|
||||
let sol_1 = Day7.rootOf input
|
||||
showSol "Solution 1" (text (toS (maybe "" Day7.name sol_1)))
|
||||
let sol_2 = Day7.solution2 input
|
||||
showSol "Solution 2" (int (maybe 0 snd sol_2))
|
||||
|
|
|
@ -19,6 +19,7 @@ library:
|
|||
- Day4
|
||||
- Day5
|
||||
- Day6
|
||||
- Day7
|
||||
dependencies:
|
||||
- base >=4.7 && <5
|
||||
- protolude
|
||||
|
@ -40,6 +41,7 @@ executables:
|
|||
- adventofcode
|
||||
- protolude
|
||||
- pretty
|
||||
- containers
|
||||
tests:
|
||||
adventofcode-test:
|
||||
main: Spec.hs
|
||||
|
|
Loading…
Reference in a new issue