From 1baf3d9615346c3c6017e3db6620286fed038059 Mon Sep 17 00:00:00 2001 From: Maciej Jur Date: Sun, 17 Dec 2023 00:00:31 +0100 Subject: [PATCH] haskell: 2023 12 b slow --- 2023/haskell/solutions/Day12.hs | 9 ++++++--- 2023/haskell/tests/Main.hs | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/2023/haskell/solutions/Day12.hs b/2023/haskell/solutions/Day12.hs index 1e815c1..70afea0 100644 --- a/2023/haskell/solutions/Day12.hs +++ b/2023/haskell/solutions/Day12.hs @@ -3,8 +3,9 @@ module Day12 where import Data.Void (Void) import Data.Text (Text) +import Data.List (intercalate) import Text.Megaparsec (Parsec, errorBundlePretty, runParser, many, eof, choice, sepBy) -import Data.Bifunctor (first) +import Data.Bifunctor (first, bimap) import Text.Megaparsec.Char (char, space, newline) import Text.Megaparsec.Char.Lexer (decimal) @@ -71,6 +72,8 @@ arrange cs@(c:cr) ns@(n:nr) solveA :: [Row] -> Int solveA = length . concatMap (uncurry arrange) --- >>> solveA <$> parse input --- Right 21 +unfold :: Row -> Row +unfold = bimap (intercalate [U] . replicate 5) (concat . replicate 5) +solveB :: [Row] -> Int +solveB = solveA . map unfold . take 5 diff --git a/2023/haskell/tests/Main.hs b/2023/haskell/tests/Main.hs index 97b9c86..77ee351 100644 --- a/2023/haskell/tests/Main.hs +++ b/2023/haskell/tests/Main.hs @@ -302,7 +302,8 @@ day12 :: Test day12 = let parsed = Day12.parse input in TestList - [ TestCase $ assertEqual "A" (Right 21) (Day12.solveA <$> parsed) + [ TestCase $ assertEqual "A" (Right 21) (Day12.solveA <$> parsed) + , TestCase $ assertEqual "B" (Right 525152) (Day12.solveB <$> parsed) ] where input =