adventofcode/app/Main.hs

98 lines
2.3 KiB
Haskell
Raw Normal View History

2017-12-01 23:27:43 +00:00
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
2017-12-01 09:41:18 +00:00
module Main where
2017-12-01 23:27:43 +00:00
import Protolude
2017-12-09 02:21:51 +00:00
2017-12-01 23:27:43 +00:00
import Text.PrettyPrint hiding ((<>))
2017-12-09 02:21:51 +00:00
import System.Environment (getArgs)
import qualified Data.Map as Map
2017-12-01 23:27:43 +00:00
import qualified Day1
2017-12-09 02:21:51 +00:00
import qualified Day2
2017-12-06 07:55:21 +00:00
import qualified Day5
2017-12-06 21:56:49 +00:00
import qualified Day6
2017-12-09 02:21:51 +00:00
import qualified Day7
2017-12-09 10:09:32 +00:00
import qualified Day8
2017-12-09 14:35:24 +00:00
import qualified Day9
2017-12-01 23:27:43 +00:00
showSol :: [Char] -> Doc -> IO ()
showSol txt d = putText . toS . render $
text (" " <> txt <> ":")
<+> d
2017-12-01 09:41:18 +00:00
main :: IO ()
2017-12-01 23:27:43 +00:00
main = do
2017-12-09 02:21:51 +00:00
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)
2017-12-09 10:09:32 +00:00
,(["8"], day8)
2017-12-09 14:35:24 +00:00
,(["9"], day9)
2017-12-09 02:21:51 +00:00
]
day1 :: IO ()
day1 = do
2017-12-01 23:27:43 +00:00
putText "Day 1:"
2017-12-06 07:55:21 +00:00
input1 <- Day1.ex1code
showSol "Solution 1" (int (Day1.solution1 input1))
showSol "Solution 2" (int (Day1.solution2 input1))
2017-12-09 02:21:51 +00:00
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
2017-12-06 07:55:21 +00:00
putText "Day 5:"
input5 <- Day5.parseInput
sol5 <- Day5.solution2 input5
showSol "Solution 2" (int sol5)
2017-12-09 02:21:51 +00:00
day6 :: IO ()
day6 = do
2017-12-06 22:07:32 +00:00
putText "Day 6:"
input6_1 <- Day6.parseInput
sol6_1 <- Day6.solution1 input6_1
showSol "Solution 1" (int sol6_1)
input6_2 <- Day6.parseInput
sol6_2 <- Day6.solution2 input6_2
showSol "Solution 2" (int sol6_2)
2017-12-09 02:21:51 +00:00
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))
2017-12-09 10:09:32 +00:00
day8 :: IO ()
day8 = do
putText "Day 8:"
input <- Day8.parseInput
let sol1 = Day8.solution1 input
showSol "Solution 1" (int sol1)
let sol2 = Day8.solution2 input
showSol "Solution 2" (int sol2)
2017-12-09 14:35:24 +00:00
day9 :: IO ()
day9 = do
putText "Day 9:"
sol1 <- Day9.solution1
showSol "Solution 1" (int sol1)
sol2 <- Day9.solution2
showSol "Solution 2" (int sol2)