diff --git a/haskell/Pre.hs b/haskell/Pre.hs index 9442292..9447da9 100644 --- a/haskell/Pre.hs +++ b/haskell/Pre.hs @@ -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) diff --git a/haskell/Puzzles/Day8.hs b/haskell/Puzzles/Day8.hs index 1c2d759..d0a730d 100644 --- a/haskell/Puzzles/Day8.hs +++ b/haskell/Puzzles/Day8.hs @@ -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) diff --git a/haskell/Puzzles/Day9.hs b/haskell/Puzzles/Day9.hs index 103ffd7..826eee3 100644 --- a/haskell/Puzzles/Day9.hs +++ b/haskell/Puzzles/Day9.hs @@ -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 } diff --git a/outputs/real/9/1 b/outputs/real/9/1 new file mode 100644 index 0000000..81825ab --- /dev/null +++ b/outputs/real/9/1 @@ -0,0 +1 @@ +4758598740 \ No newline at end of file