haskell: 2023 12 b slow

This commit is contained in:
Maciej Jur 2023-12-17 00:00:31 +01:00
parent 942cb7d32e
commit 1baf3d9615
Signed by: kamov
GPG key ID: 191CBFF5F72ECAFD
2 changed files with 8 additions and 4 deletions

View file

@ -3,8 +3,9 @@ module Day12 where
import Data.Void (Void) import Data.Void (Void)
import Data.Text (Text) import Data.Text (Text)
import Data.List (intercalate)
import Text.Megaparsec (Parsec, errorBundlePretty, runParser, many, eof, choice, sepBy) 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 (char, space, newline)
import Text.Megaparsec.Char.Lexer (decimal) import Text.Megaparsec.Char.Lexer (decimal)
@ -71,6 +72,8 @@ arrange cs@(c:cr) ns@(n:nr)
solveA :: [Row] -> Int solveA :: [Row] -> Int
solveA = length . concatMap (uncurry arrange) solveA = length . concatMap (uncurry arrange)
-- >>> solveA <$> parse input unfold :: Row -> Row
-- Right 21 unfold = bimap (intercalate [U] . replicate 5) (concat . replicate 5)
solveB :: [Row] -> Int
solveB = solveA . map unfold . take 5

View file

@ -302,7 +302,8 @@ day12 :: Test
day12 = day12 =
let parsed = Day12.parse input let parsed = Day12.parse input
in TestList 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 where
input = input =