Solve day 9 part 1
This commit is contained in:
parent
ce70643476
commit
c608e21e26
@ -37,6 +37,7 @@ module Pre (
|
||||
digit,
|
||||
digitsToInt,
|
||||
listIndex,
|
||||
allUnorderedPairs,
|
||||
)
|
||||
where
|
||||
|
||||
@ -106,3 +107,6 @@ listIndex n =
|
||||
else \case
|
||||
[] -> Nothing
|
||||
x : xs -> if n == 0 then Just x else listIndex (n - 1) xs
|
||||
|
||||
allUnorderedPairs :: [a] -> [(a, a)]
|
||||
allUnorderedPairs = concat . join (zipWith (flip $ map . (,)) . tail . tails)
|
||||
|
||||
@ -41,6 +41,3 @@ connectBoxes :: [V3 Int] -> [((V3 Int, V3 Int), DS.DisjointSet (V3 Int))]
|
||||
connectBoxes boxes = zip allPairs $ scanl (flip $ uncurry DS.union) (foldMap DS.singleton boxes) allPairs
|
||||
where
|
||||
allPairs = sortOn (quadrance . uncurry (-)) $ allUnorderedPairs boxes
|
||||
|
||||
allUnorderedPairs :: [a] -> [(a, a)]
|
||||
allUnorderedPairs = concat . join (zipWith (flip $ map . (,)) . tail . tails)
|
||||
|
||||
@ -2,14 +2,20 @@ module Puzzles.Day9 (puzzle) where
|
||||
|
||||
import Pre
|
||||
|
||||
import Data.Text.Lazy qualified as TL
|
||||
|
||||
puzzle :: Puzzle
|
||||
puzzle =
|
||||
Puzzle
|
||||
{ number = 9
|
||||
, parser = mempty
|
||||
, parser = const $ (V2 @Int <$> decimal <* single ',' <*> decimal) `sepEndBy1` newline
|
||||
, parts =
|
||||
[ \() ->
|
||||
"TODO"
|
||||
[ TL.show
|
||||
. maximum
|
||||
. fmap ((\(V2 x y) -> x * y) . (+ 1) . fmap abs . uncurry (-))
|
||||
. fromMaybe (error "empty input")
|
||||
. nonEmpty
|
||||
. allUnorderedPairs
|
||||
]
|
||||
, extraTests = mempty
|
||||
}
|
||||
|
||||
1
outputs/real/9/1
Normal file
1
outputs/real/9/1
Normal file
@ -0,0 +1 @@
|
||||
4758598740
|
||||
Loading…
x
Reference in New Issue
Block a user