Day 10: Optimization
This commit is contained in:
parent
9587504a13
commit
66fd0ab19e
@ -6,12 +6,13 @@ main = do
|
|||||||
input <- map read . lines <$> readFile "input"
|
input <- map read . lines <$> readFile "input"
|
||||||
print $ (product . map length . group . sort . jolts) input
|
print $ (product . map length . group . sort . jolts) input
|
||||||
print $
|
print $
|
||||||
(product . map (arrangements . sum) . filter (elem 1) . group . jolts) input
|
(product .
|
||||||
|
map (last . trib [0, 0, 1] . sum) . filter (elem 1) . group . jolts)
|
||||||
|
input
|
||||||
|
|
||||||
arrangements :: Int -> Int
|
jolts :: [Integer] -> [Integer]
|
||||||
arrangements =
|
|
||||||
(\x -> length . filter (== x)) <*>
|
|
||||||
(map sum . nub . map (filter (/= 0)) . flip replicateM [0 .. 3])
|
|
||||||
|
|
||||||
jolts :: [Int] -> [Int]
|
|
||||||
jolts = ap (zipWith subtract) tail . (\x -> 0 : x ++ [last x + 3]) . sort
|
jolts = ap (zipWith subtract) tail . (\x -> 0 : x ++ [last x + 3]) . sort
|
||||||
|
|
||||||
|
trib :: [Integer] -> Integer -> [Integer]
|
||||||
|
trib x 0 = x
|
||||||
|
trib [x, y, z] n = trib [y, z, x + y + z] (n - 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user