haskell: 2023 12 b slow
This commit is contained in:
parent
942cb7d32e
commit
1baf3d9615
|
@ -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
|
||||
|
|
|
@ -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 =
|
||||
|
|
Loading…
Reference in a new issue