renaming for sorting issue
This commit is contained in:
parent
6ee22fa9cc
commit
31a1dceadd
13 changed files with 113 additions and 113 deletions
|
@ -28,15 +28,15 @@ library
|
|||
hs-source-dirs:
|
||||
src
|
||||
exposed-modules:
|
||||
Day1
|
||||
Day2
|
||||
Day3
|
||||
Day4
|
||||
Day5
|
||||
Day6
|
||||
Day7
|
||||
Day8
|
||||
Day9
|
||||
Day01
|
||||
Day02
|
||||
Day03
|
||||
Day04
|
||||
Day05
|
||||
Day06
|
||||
Day07
|
||||
Day08
|
||||
Day09
|
||||
Day10
|
||||
other-modules:
|
||||
Paths_adventofcode
|
||||
|
|
112
app/Main.hs
112
app/Main.hs
|
@ -8,13 +8,13 @@ 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
|
||||
import qualified Day8
|
||||
import qualified Day9
|
||||
import qualified Day01
|
||||
import qualified Day02
|
||||
import qualified Day05
|
||||
import qualified Day06
|
||||
import qualified Day07
|
||||
import qualified Day08
|
||||
import qualified Day09
|
||||
import qualified Day10
|
||||
|
||||
showSol :: [Char] -> Doc -> IO ()
|
||||
|
@ -29,73 +29,73 @@ main = do
|
|||
(Map.lookup args solutions)
|
||||
|
||||
solutions :: Map [[Char]] (IO ())
|
||||
solutions = Map.fromList [(["1"], day1)
|
||||
,(["2"], day2)
|
||||
,(["5"], day5)
|
||||
,(["6"], day6)
|
||||
,(["7"], day7)
|
||||
,(["8"], day8)
|
||||
,(["9"], day9)
|
||||
solutions = Map.fromList [(["01"], day01)
|
||||
,(["02"], day02)
|
||||
,(["05"], day05)
|
||||
,(["06"], day06)
|
||||
,(["07"], day07)
|
||||
,(["08"], day08)
|
||||
,(["09"], day09)
|
||||
,(["10"], day10)
|
||||
]
|
||||
|
||||
day1 :: IO ()
|
||||
day1 = do
|
||||
putText "Day 1:"
|
||||
input1 <- Day1.ex1code
|
||||
showSol "Solution 1" (int (Day1.solution1 input1))
|
||||
showSol "Solution 2" (int (Day1.solution2 input1))
|
||||
day01 :: IO ()
|
||||
day01 = do
|
||||
putText "Day 01:"
|
||||
input1 <- Day01.ex1code
|
||||
showSol "Solution 1" (int (Day01.solution1 input1))
|
||||
showSol "Solution 2" (int (Day01.solution2 input1))
|
||||
|
||||
day2 :: IO ()
|
||||
day2 = do
|
||||
putText "Day 2:"
|
||||
input <- Day2.parseInput
|
||||
let sol1 = maybe 0 Day2.solution1 input
|
||||
day02 :: IO ()
|
||||
day02 = do
|
||||
putText "Day 02:"
|
||||
input <- Day02.parseInput
|
||||
let sol1 = maybe 0 Day02.solution1 input
|
||||
showSol "Solution 1" (integer sol1)
|
||||
let sol2 = maybe 0 Day2.solution2 input
|
||||
let sol2 = maybe 0 Day02.solution2 input
|
||||
showSol "Solution 2" (integer sol2)
|
||||
|
||||
day5 :: IO ()
|
||||
day5 = do
|
||||
putText "Day 5:"
|
||||
input5 <- Day5.parseInput
|
||||
sol5 <- Day5.solution2 input5
|
||||
day05 :: IO ()
|
||||
day05 = do
|
||||
putText "Day 05:"
|
||||
input5 <- Day05.parseInput
|
||||
sol5 <- Day05.solution2 input5
|
||||
showSol "Solution 2" (int sol5)
|
||||
|
||||
day6 :: IO ()
|
||||
day6 = do
|
||||
putText "Day 6:"
|
||||
input6_1 <- Day6.parseInput
|
||||
sol6_1 <- Day6.solution1 input6_1
|
||||
day06 :: IO ()
|
||||
day06 = do
|
||||
putText "Day 06:"
|
||||
input6_1 <- Day06.parseInput
|
||||
sol6_1 <- Day06.solution1 input6_1
|
||||
showSol "Solution 1" (int sol6_1)
|
||||
input6_2 <- Day6.parseInput
|
||||
sol6_2 <- Day6.solution2 input6_2
|
||||
input6_2 <- Day06.parseInput
|
||||
sol6_2 <- Day06.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
|
||||
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
|
||||
showSol "Solution 2" (int (maybe 0 snd sol_2))
|
||||
|
||||
day8 :: IO ()
|
||||
day8 = do
|
||||
putText "Day 8:"
|
||||
input <- Day8.parseInput
|
||||
let sol1 = Day8.solution1 input
|
||||
day08 :: IO ()
|
||||
day08 = do
|
||||
putText "Day 08:"
|
||||
input <- Day08.parseInput
|
||||
let sol1 = Day08.solution1 input
|
||||
showSol "Solution 1" (int sol1)
|
||||
let sol2 = Day8.solution2 input
|
||||
let sol2 = Day08.solution2 input
|
||||
showSol "Solution 2" (int sol2)
|
||||
|
||||
day9 :: IO ()
|
||||
day9 = do
|
||||
putText "Day 9:"
|
||||
sol1 <- Day9.solution1
|
||||
day09 :: IO ()
|
||||
day09 = do
|
||||
putText "Day 09:"
|
||||
sol1 <- Day09.solution1
|
||||
showSol "Solution 1" (int sol1)
|
||||
sol2 <- Day9.solution2
|
||||
sol2 <- Day09.solution2
|
||||
showSol "Solution 2" (int sol2)
|
||||
|
||||
day10 :: IO ()
|
||||
|
|
18
package.yaml
18
package.yaml
|
@ -13,15 +13,15 @@ extra-source-files:
|
|||
library:
|
||||
source-dirs: src
|
||||
exposed-modules:
|
||||
- Day1
|
||||
- Day2
|
||||
- Day3
|
||||
- Day4
|
||||
- Day5
|
||||
- Day6
|
||||
- Day7
|
||||
- Day8
|
||||
- Day9
|
||||
- Day01
|
||||
- Day02
|
||||
- Day03
|
||||
- Day04
|
||||
- Day05
|
||||
- Day06
|
||||
- Day07
|
||||
- Day08
|
||||
- Day09
|
||||
- Day10
|
||||
dependencies:
|
||||
- base >=4.7 && <5
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{-# LANGUAGE NoImplicitPrelude #-}
|
||||
module Day1 where
|
||||
module Day01 where
|
||||
|
||||
import Protolude
|
||||
|
|
@ -45,7 +45,7 @@ In this example, the sum of the results would be 4 + 3 + 2 = 9.
|
|||
|
||||
What is the sum of each row's result in your puzzle input?
|
||||
|-}
|
||||
module Day2 where
|
||||
module Day02 where
|
||||
|
||||
import Protolude
|
||||
import qualified Control.Foldl as F
|
|
@ -49,7 +49,7 @@ What is the first value written that is larger than your puzzle input?
|
|||
|
||||
|
||||
|-}
|
||||
module Day3 where
|
||||
module Day03 where
|
||||
|
||||
import Protolude
|
||||
import qualified Control.Foldl as F
|
|
@ -34,7 +34,7 @@ oiii ioii iioi iiio is not valid - any of these words can be rearranged to form
|
|||
Under this new system policy, how many passphrases are valid?
|
||||
|
||||
|-}
|
||||
module Day4 where
|
||||
module Day04 where
|
||||
|
||||
import Protolude
|
||||
import qualified Data.Text as Text
|
|
@ -52,7 +52,7 @@ offset values after finding the exit are left as 2 3 2 3 -1.
|
|||
|
||||
How many steps does it now take to reach the exit?
|
||||
|-}
|
||||
module Day5 where
|
||||
module Day05 where
|
||||
|
||||
import Protolude
|
||||
|
|
@ -59,7 +59,7 @@ How many cycles are in the infinite loop that arises from the configuration in
|
|||
your puzzle input?
|
||||
|
||||
|-}
|
||||
module Day6 where
|
||||
module Day06 where
|
||||
|
||||
import Protolude
|
||||
|
|
@ -104,7 +104,7 @@ to be to balance the entire tower?
|
|||
|
||||
|
||||
|-}
|
||||
module Day7 where
|
||||
module Day07 where
|
||||
|
||||
import Protolude
|
||||
|
|
@ -35,7 +35,7 @@ What is the largest value in any register after completing the instructions in
|
|||
your puzzle input?
|
||||
|
||||
|-}
|
||||
module Day8 where
|
||||
module Day08 where
|
||||
|
||||
import Protolude hiding ((<|>),many)
|
||||
|
|
@ -82,7 +82,7 @@ characters or the ! doing the canceling.
|
|||
How many non-canceled characters are within the garbage in your puzzle input?
|
||||
|
||||
|-}
|
||||
module Day9 where
|
||||
module Day09 where
|
||||
|
||||
import Protolude hiding ((<|>),many)
|
||||
|
60
test/Spec.hs
60
test/Spec.hs
|
@ -4,12 +4,12 @@ import Test.Tasty
|
|||
import Test.Tasty.HUnit
|
||||
import Control.Monad (when)
|
||||
|
||||
import qualified Day1
|
||||
import qualified Day2
|
||||
import qualified Day5
|
||||
import qualified Day6
|
||||
import qualified Day7
|
||||
import qualified Day8
|
||||
import qualified Day01
|
||||
import qualified Day02
|
||||
import qualified Day05
|
||||
import qualified Day06
|
||||
import qualified Day07
|
||||
import qualified Day08
|
||||
import qualified Day10
|
||||
|
||||
|
||||
|
@ -19,67 +19,67 @@ main = defaultMain $
|
|||
[
|
||||
testGroup "Day 1"
|
||||
[ testGroup "solution 1"
|
||||
[ testCase "1122 is 3" $ Day1.solution1 "1122" @?= 3
|
||||
, testCase "1111 is 4" $ Day1.solution1 "1111" @?= 4
|
||||
, testCase "1234 is 0" $ Day1.solution1 "1234" @?= 0
|
||||
, testCase "91212129 is 9" $ Day1.solution1 "91212129" @?= 9
|
||||
[ testCase "1122 is 3" $ Day01.solution1 "1122" @?= 3
|
||||
, testCase "1111 is 4" $ Day01.solution1 "1111" @?= 4
|
||||
, testCase "1234 is 0" $ Day01.solution1 "1234" @?= 0
|
||||
, testCase "91212129 is 9" $ Day01.solution1 "91212129" @?= 9
|
||||
]
|
||||
, testGroup "solution 2"
|
||||
[ testCase "1212 is 6" $ Day1.solution2 "1212" @?= 6
|
||||
, testCase "1221 is 0" $ Day1.solution2 "1221" @?= 0
|
||||
, testCase "123425 is 0" $ Day1.solution2 "123425" @?= 4
|
||||
, testCase "123123 is 12" $ Day1.solution2 "123123" @?= 12
|
||||
, testCase "12131415 is 4" $ Day1.solution2 "12131415" @?= 4
|
||||
[ testCase "1212 is 6" $ Day01.solution2 "1212" @?= 6
|
||||
, testCase "1221 is 0" $ Day01.solution2 "1221" @?= 0
|
||||
, testCase "123425 is 0" $ Day01.solution2 "123425" @?= 4
|
||||
, testCase "123123 is 12" $ Day01.solution2 "123123" @?= 12
|
||||
, testCase "12131415 is 4" $ Day01.solution2 "12131415" @?= 4
|
||||
]
|
||||
]
|
||||
, testGroup "Day 2"
|
||||
[ testCase "example problem 1" $
|
||||
Day2.solution1 [[5,1,9,5],[7,5,3],[2,4,6,8]] @?= 18
|
||||
Day02.solution1 [[5,1,9,5],[7,5,3],[2,4,6,8]] @?= 18
|
||||
, testCase "example problem 2" $
|
||||
Day2.solution2 [[5,9,2,8],[9,4,7,3],[3,8,6,5]] @?= 9
|
||||
Day02.solution2 [[5,9,2,8],[9,4,7,3],[3,8,6,5]] @?= 9
|
||||
]
|
||||
, testGroup "Day 5"
|
||||
[ testCaseSteps "example problem 1" $ \step -> do
|
||||
step "Loading input"
|
||||
input <- Day5.testArray
|
||||
input <- Day05.testArray
|
||||
step "Running solution 1"
|
||||
sol1 <- Day5.solution1 input
|
||||
sol1 <- Day05.solution1 input
|
||||
when (sol1 /= 5) (assertFailure "Should be 5 steps")
|
||||
, testCaseSteps "example problem 2" $ \step -> do
|
||||
step "Loading input"
|
||||
input <- Day5.testArray
|
||||
input <- Day05.testArray
|
||||
step "Running solution 2"
|
||||
sol2 <- Day5.solution2 input
|
||||
sol2 <- Day05.solution2 input
|
||||
when (sol2 /= 10) (assertFailure "Day 6 solution 2 on the example should be 4")
|
||||
]
|
||||
, testGroup "Day 6"
|
||||
[ testCaseSteps "example problem 1" $ \step -> do
|
||||
step "Loading input"
|
||||
input <- Day6.testArray
|
||||
input <- Day06.testArray
|
||||
step "Running solution 1"
|
||||
sol1 <- Day6.solution1 input
|
||||
sol1 <- Day06.solution1 input
|
||||
when (sol1 /= 5) (assertFailure "Should be 5 steps")
|
||||
, testCaseSteps "example problem 2" $ \step -> do
|
||||
step "Loading input"
|
||||
input <- Day6.testArray
|
||||
input <- Day06.testArray
|
||||
step "Running solution 2"
|
||||
sol2 <- Day6.solution2 input
|
||||
sol2 <- Day06.solution2 input
|
||||
when (sol2 /= 4) (assertFailure "Day 6 solution 2 on the example should be 4")
|
||||
]
|
||||
, testGroup "Day 7"
|
||||
[ testCaseSteps "example problem 1" $ \step -> do
|
||||
step "Running solution 1"
|
||||
let input = Day7.testNodes
|
||||
let sol1 = maybe "" Day7.name (Day7.rootOf input)
|
||||
let input = Day07.testNodes
|
||||
let sol1 = maybe "" Day07.name (Day07.rootOf input)
|
||||
when (sol1 /= "tknk") (assertFailure "The root should be tknk")
|
||||
, testCase "example on solution 2" $
|
||||
maybe 0 snd (Day7.solution2 Day7.testNodes) @?= 60
|
||||
maybe 0 snd (Day07.solution2 Day07.testNodes) @?= 60
|
||||
]
|
||||
, testGroup "Day 8"
|
||||
[ testCase "example problem 1" $
|
||||
Day8.solution1 Day8.testInstructions @?= 1
|
||||
Day08.solution1 Day08.testInstructions @?= 1
|
||||
, testCase "example problem 1" $
|
||||
Day8.solution2 Day8.testInstructions @?= 10
|
||||
Day08.solution2 Day08.testInstructions @?= 10
|
||||
]
|
||||
, testGroup "Day 10"
|
||||
[ testCase "example 1" $
|
||||
|
|
Loading…
Reference in a new issue