From 7058b3ffd2b29071ba10e940514f4688ade93759 Mon Sep 17 00:00:00 2001 From: HeNine <> Date: Sat, 3 Dec 2022 10:01:46 +0100 Subject: [PATCH] day3 --- aoc2022.cabal | 34 ++++- data/input030.txt | 6 + data/input031.txt | 300 ++++++++++++++++++++++++++++++++++++++ src/day03/Day3Lib.hs | 23 +++ src/day03/test/AoCTest.hs | 41 ++++++ src/day03/test/Basic.hs | 19 +++ 6 files changed, 420 insertions(+), 3 deletions(-) create mode 100644 data/input030.txt create mode 100644 data/input031.txt create mode 100644 src/day03/Day3Lib.hs create mode 100644 src/day03/test/AoCTest.hs create mode 100644 src/day03/test/Basic.hs diff --git a/aoc2022.cabal b/aoc2022.cabal index 08b48f1..14d1c5a 100644 --- a/aoc2022.cabal +++ b/aoc2022.cabal @@ -18,7 +18,8 @@ test-suite day01aoctest type: exitcode-stdio-1.0 hs-source-dirs: src/day01/test, src/day01 main-is: AoCTest.hs - other-modules: Day1Lib + other-modules: + Day1Lib build-depends: base , HUnit , split @@ -65,7 +66,8 @@ test-suite day02aoctest type: exitcode-stdio-1.0 hs-source-dirs: src/day02/test, src/day02 main-is: AoCTest.hs - other-modules: Day2Lib + other-modules: + Day2Lib build-depends: base , HUnit ghc-options: -threaded -rtsopts -with-rtsopts=-N @@ -103,4 +105,30 @@ executable day022 -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields - -Wredundant-constraints \ No newline at end of file + -Wredundant-constraints + +-- Day 3 + +test-suite day03basictest + type: exitcode-stdio-1.0 + hs-source-dirs: src/day03/test, src/day03 + main-is: Basic.hs + other-modules: + Day3Lib + build-depends: base + , HUnit + , split + ghc-options: -threaded -rtsopts -with-rtsopts=-N + default-language: Haskell2010 + +test-suite day03aoctest + type: exitcode-stdio-1.0 + hs-source-dirs: src/day03/test, src/day03 + main-is: AoCTest.hs + other-modules: + Day3Lib + build-depends: base + , HUnit + , split + ghc-options: -threaded -rtsopts -with-rtsopts=-N + default-language: Haskell2010 \ No newline at end of file diff --git a/data/input030.txt b/data/input030.txt new file mode 100644 index 0000000..40543a9 --- /dev/null +++ b/data/input030.txt @@ -0,0 +1,6 @@ +vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw \ No newline at end of file diff --git a/data/input031.txt b/data/input031.txt new file mode 100644 index 0000000..efc5af8 --- /dev/null +++ b/data/input031.txt @@ -0,0 +1,300 @@ +VdzVHmNpdVmBBCpmQLTNfTtMhMJnhFhTTf +FgqsZbqDDFqRrhhJnsnLMTfhJG +bRRRPrRRwSwbDqgjvDZbRbQzpzmQVWCzzBdvQBFCzlWV +GcDdRdvhRssRhGDdShCRtqWjlQzqWgqzNfNjfQWWjt +mwwnnPFwmVrPmJmzfNzqCjQCbgVlgC +nPnHHLrHwmJTrCTJpThBscBSdSLGZvZBvRhZ +RVQQcVlcSRclfZCCCnMJJTSTnC +NdHwjdwjbBBZrrZrbJDZJJ +wmhjGGBGwwmjtjtdPlfRcpVQlhRppVJF +pplbNBPPrppllrFNbpvppSTcwqcWFhTTShhJDTchqd +RGzRfLjjmZmfmwLftTWhStStJWTdWmDm +nfsMjQssnpPvNnrPrw +SjjBgllzlQjBZvlBBgcFbgJHsMhJqbMHPggJbM +hRLRVDdRRWnJqnnHTqMCnH +GRfLddRRpVhNVrWSjwQQzSzcGSBQSc +qMwNqqBdQdnTVBBVVhMVnVFzTHPggTPjGRDzvPTjjmvPDj +sbSrWJpStrtPtRPttzmmDD +pfbJJcbsrcLpWLllsnFmcqcwQncnQQqVNQ +RBTWCMwCwdZThPZcZZ +pVmVpHLFFFHHVgVmvNmHSQNvddlPPzZJMPcdhclhjczLdZMP +vnnNnFStGMRDwWnn +fWDdJTpDJzdBBBdmDSbSRHRwPqbPbHgSbz +slQtQvNsMVvrrgPRgRglnhwWPH +sGM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lclnRSDnGZtvSwnZDZzhLffqdsCNwTBCBBdNsd +mPjmjmrFFpmQjMJQjlNdlhCsCLsTlNLs +ggmrHHVVQVPJpWrgpWScRvzZzGGRnZvlgzZn +GjGJGQJGcMTVfFDQzNVQzP +mHqdbmmdnJqVzVhRVNzPbR +wStmHJsJsLZLjTvM +QssMbVGdMQjZPjwVwHVZPZClllvgSgvlTgwwSSCgSCtC +WmmFBmJrcFRBFrJJBFchzWCStgCTgvhvTlfsNqfTlvTv +sFzzssDLzrBPjDVVddHMQD +fztDZSGrNrlnbnPTgFFpln +jvvQMMcLcjJmQwHdJvjQJnnbTbRFRphnnpsWgmFRPR +vTLHHCQLHBBjJCSZrVCZtSfSfrft +gHfHffHLjwHrRjLrLRZVMnTdTBsNTBwTVBsBnN +DWPhqhhDhvSGvWPzSzMBQBQVMMBBmvssvQvQ +CDGbqCDbChSbWGrHcHRgbcVcfrLJ +frlTLmtllbbbdpJS +qFjhzjThjHTFGHTjqhhjMzBhVpVpdbBnSJQRpBnVVdbRRQJd +vjWPWjWPPPWgwmfCrNvTvZ \ No newline at end of file diff --git a/src/day03/Day3Lib.hs b/src/day03/Day3Lib.hs new file mode 100644 index 0000000..8a3a82e --- /dev/null +++ b/src/day03/Day3Lib.hs @@ -0,0 +1,23 @@ +module Day3Lib + ( score, + -- + processInput1, + processInput2, + ) +where + +import Data.Char (isLower, ord) +import Data.List (intersect) +import Data.List.Split (chunksOf) + +score c = if isLower c then ord c - ord 'a' + 1 else ord c - ord 'A' + 27 + +-- ################### + +processInput1 = sum . (map processLine1) . lines + +processLine1 r = score . head $ intersect (take ((length r) `div` 2) r) (drop ((length r) `div` 2) r) + +processInput2 = sum . (map processChunk2) . (chunksOf 3) . lines + +processChunk2 [a, b, c] = score . head . (intersect c) $ intersect a b diff --git a/src/day03/test/AoCTest.hs b/src/day03/test/AoCTest.hs new file mode 100644 index 0000000..4e73274 --- /dev/null +++ b/src/day03/test/AoCTest.hs @@ -0,0 +1,41 @@ +import Day3Lib (processInput1, processInput2) +import System.IO +import Test.HUnit + +testCases1 = + [ ("data/input030.txt", 157), + ("data/input031.txt", 8153) + ] + +testCase1 (file, result) = do + withFile + file + ReadMode + ( \handle -> do + contents <- hGetContents handle + assertEqual "input test" result $ processInput1 contents + ) + +testCases2 = + [ ("data/input030.txt", 70), + ("data/input031.txt", 2342) + ] + +testCase2 (file, result) = do + withFile + file + ReadMode + ( \handle -> do + contents <- hGetContents handle + assertEqual "input test" result $ processInput2 contents + ) + +tests = + TestList $ + [TestCase (testCase1 c) | c <- testCases1] + ++ [TestCase (testCase2 c) | c <- testCases2] + +main :: IO () +main = do + runTestTT tests + return () diff --git a/src/day03/test/Basic.hs b/src/day03/test/Basic.hs new file mode 100644 index 0000000..b620363 --- /dev/null +++ b/src/day03/test/Basic.hs @@ -0,0 +1,19 @@ +import Day3Lib +import Test.HUnit + +ta = TestCase (assertEqual "a" 1 $ score 'a') + +tz = TestCase (assertEqual "z" 26 $ score 'z') + +tA = TestCase (assertEqual "A" 27 $ score 'A') + +tZ = TestCase (assertEqual "Z" 52 $ score 'Z') + +tests = + TestList $ + [ta, tz, tA, tZ] + +main :: IO () +main = do + runTestTT tests + return ()