adventofcode/app/Main.hs

207 lines
5.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
2017-12-11 14:59:07 +00:00
import qualified Day01
import qualified Day02
import qualified Day03
import qualified Day04
2017-12-11 14:59:07 +00:00
import qualified Day05
import qualified Day06
import qualified Day07
import qualified Day08
import qualified Day09
2017-12-10 12:07:53 +00:00
import qualified Day10
2017-12-11 15:36:18 +00:00
import qualified Day11
2017-12-12 10:04:43 +00:00
import qualified Day12
import qualified Day13
2017-12-14 20:17:31 +00:00
import qualified Day14
2017-12-15 05:53:13 +00:00
import qualified Day15
2017-12-17 02:01:29 +00:00
import qualified Day16
2017-12-20 23:45:37 +00:00
import qualified Day17
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 ())
2017-12-11 14:59:07 +00:00
solutions = Map.fromList [(["01"], day01)
,(["02"], day02)
,(["03"], day03)
,(["04"], day04)
2017-12-11 14:59:07 +00:00
,(["05"], day05)
,(["06"], day06)
,(["07"], day07)
,(["08"], day08)
,(["09"], day09)
2017-12-10 12:07:53 +00:00
,(["10"], day10)
2017-12-11 15:36:18 +00:00
,(["11"], day11)
2017-12-12 10:04:43 +00:00
,(["12"], day12)
,(["13"], day13)
2017-12-14 20:17:31 +00:00
,(["14"], day14)
2017-12-15 05:53:13 +00:00
,(["15"], day15)
2017-12-17 02:01:29 +00:00
,(["16"], day16)
2017-12-20 23:45:37 +00:00
,(["17"], day17)
2017-12-09 02:21:51 +00:00
]
-- | Show ZERO in case of failure
mint = int . fromMaybe 0
-- | Show ZERO in case of failure
minteger = integer . fromMaybe 0
2017-12-11 14:59:07 +00:00
day01 :: IO ()
day01 = do
putText "Day 01:"
input1 <- Day01.ex1code
showSol "Solution 1" (int (Day01.solution1 input1))
showSol "Solution 2" (int (Day01.solution2 input1))
2017-12-09 02:21:51 +00:00
2017-12-11 14:59:07 +00:00
day02 :: IO ()
day02 = do
putText "Day 02:"
input <- Day02.parseInput
let sol1 = maybe 0 Day02.solution1 input
2017-12-09 02:21:51 +00:00
showSol "Solution 1" (integer sol1)
2017-12-11 14:59:07 +00:00
let sol2 = maybe 0 Day02.solution2 input
2017-12-09 02:21:51 +00:00
showSol "Solution 2" (integer sol2)
day03 :: IO ()
day03 = do
putText "Day 03:"
showSol "Solution 1" (minteger (Day03.solution1 Day03.input))
showSol "Solution 2" (minteger (Day03.solution2 (fromIntegral Day03.input)))
day04 :: IO ()
day04 = do
putText "Day 04:"
input <- Day04.parseInput
let sol1 = Day04.solution1 input
showSol "Solution 1" (int sol1)
let sol2 = Day04.solution2 input
showSol "Solution 2" (int sol2)
2017-12-11 14:59:07 +00:00
day05 :: IO ()
day05 = do
putText "Day 05:"
input5 <- Day05.parseInput
sol5 <- Day05.solution2 input5
2017-12-06 07:55:21 +00:00
showSol "Solution 2" (int sol5)
2017-12-09 02:21:51 +00:00
2017-12-11 14:59:07 +00:00
day06 :: IO ()
day06 = do
putText "Day 06:"
input6_1 <- Day06.parseInput
sol6_1 <- Day06.solution1 input6_1
2017-12-06 22:07:32 +00:00
showSol "Solution 1" (int sol6_1)
2017-12-11 14:59:07 +00:00
input6_2 <- Day06.parseInput
sol6_2 <- Day06.solution2 input6_2
2017-12-06 22:07:32 +00:00
showSol "Solution 2" (int sol6_2)
2017-12-09 02:21:51 +00:00
2017-12-11 14:59:07 +00:00
day07 :: IO ()
day07 = do
putText "Day 07:"
input <- Day07.parseInput
let sol_1 = Day07.rootOf input
showSol "Solution 1" (text (toS (maybe "" Day07.name sol_1)))
let sol_2 = Day07.solution2 input
2017-12-09 02:21:51 +00:00
showSol "Solution 2" (int (maybe 0 snd sol_2))
2017-12-09 10:09:32 +00:00
2017-12-11 14:59:07 +00:00
day08 :: IO ()
day08 = do
putText "Day 08:"
input <- Day08.parseInput
let sol1 = Day08.solution1 input
2017-12-09 10:09:32 +00:00
showSol "Solution 1" (int sol1)
2017-12-11 14:59:07 +00:00
let sol2 = Day08.solution2 input
2017-12-09 10:09:32 +00:00
showSol "Solution 2" (int sol2)
2017-12-09 14:35:24 +00:00
2017-12-11 14:59:07 +00:00
day09 :: IO ()
day09 = do
putText "Day 09:"
input <- Day09.parseInput
let sol1 = Day09.solution1 input
2017-12-09 14:35:24 +00:00
showSol "Solution 1" (int sol1)
let sol2 = Day09.solution2 input
2017-12-09 14:35:24 +00:00
showSol "Solution 2" (int sol2)
2017-12-10 12:07:53 +00:00
day10 :: IO ()
day10 = do
putText "Day 10:"
let sol1 = Day10.solution1 Day10.input
showSol "Solution 1" (int sol1)
2017-12-10 13:41:52 +00:00
input2 <- Day10.parseInput2
showSol "Solution 2" (text (toS (Day10.solution2 input2)))
2017-12-11 15:36:18 +00:00
day11 :: IO ()
day11 = do
putText "Day 11:"
input <- Day11.parseInput
let sol1 = Day11.solution1 input
showSol "Solution 1" (int sol1)
2017-12-12 10:04:43 +00:00
day12 :: IO ()
day12 = do
putText "Day 12:"
input <- Day12.parseInput
let sol1 = fmap Day12.solution1 input
showSol "Solution 1" (int (fromMaybe 0 sol1))
let sol2 = fmap Day12.solution2 input
showSol "Solution 2" (int (fromMaybe 0 sol2))
day13 :: IO ()
day13 = do
putText "Day 13:"
input <- Day13.input
let sol1 = fmap Day13.solution1 input
showSol "Solution 1" (int (fromMaybe 0 sol1))
input2 <- Day13.parseInput
let sol2 = Day13.solution2 =<< input2
showSol "Solution 2" (int (fromMaybe 0 sol2))
2017-12-14 20:17:31 +00:00
day14 :: IO ()
day14 = do
putText "Day 14:"
let sol1 = Day14.solution1 Day14.input
showSol "Solution 1" (int (fromMaybe 0 sol1))
sol2 <- Day14.solution2 Day14.input
showSol "Solution 2" (int sol2)
2017-12-15 05:53:13 +00:00
day15 :: IO ()
day15 = do
putText "Day 15:"
let sol1 = Day15.solution1 Day15.input
showSol "Solution 1" (int sol1)
let sol2 = Day15.solution2 Day15.input
2017-12-20 23:45:37 +00:00
showSol "Solution 2" (int sol2)
2017-12-17 02:01:29 +00:00
day16 :: IO ()
day16 = do
putText "Day 16:"
input <- Day16.parseInput
sol1 <- Day16.solution1 16 input
showSol "Solution 1" (text (toS sol1))
2017-12-20 23:45:37 +00:00
-- sol2 <- Day16.solution2 16 input
-- showSol "Solution 2" (text (toS sol2))
day17 :: IO ()
day17 = do
putText "Day 17:"
2017-12-21 11:45:40 +00:00
let sol1 = Day17.solution1 2017 Day17.input
2017-12-20 23:45:37 +00:00
showSol "Solution 1" (int (fromMaybe 0 sol1))
let sol2 = Day17.solution2 50000000 Day17.input
showSol "Solution 2" (int sol2)