From bd551f90974ea7901e0e259d9e85b050b6c14b57 Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Wed, 11 Dec 2024 21:33:52 -0800 Subject: [PATCH] 2024-12 --- inputs/2024/12.txt | 140 ++++++++++++++++++++++++++++++++++++++ solutions/solutions.cabal | 5 ++ solutions/src/2024/12.hs | 55 +++++++++++++++ 3 files changed, 200 insertions(+) create mode 100644 inputs/2024/12.txt create mode 100644 solutions/src/2024/12.hs diff --git a/inputs/2024/12.txt b/inputs/2024/12.txt new file mode 100644 index 0000000..cdc305e --- /dev/null +++ b/inputs/2024/12.txt @@ -0,0 +1,140 @@ +OBBBBLLLLLLVVVVVVVVVVVVVVMMMMMMMMMMMMMMMMMMMMMJJJJJJJJJJOOOOOOORRRRRRRRRRRRRRRRRRRRXXXXXXXXXXXXXXXUUUUXBXXAXXDDDDDDNNNNNNNNNNNNNNNNTTTLHHLLL +OBBBBBLLLLLLVVVVVVVVVVVVVVVVSSMMVVVMVVMMMMMMMMLJJJJJJJJJOOOORRRRRRRRRRRRRRRRRRRRRRRXXXXXXXXXXXXXXXUUXUXBXXXXXDDDDDDNNNNNNNNNNNNNNONTLLLLLLLL +OBBBBBLLLLKKKKKVVVVVVVVVVFVSSSSMMMVVVVVMMMMMMMLLJJJJJJJJJOOOOORRRRRRRRRRRRRRRRRRRRDDDXXXXXXXXXXXJXXXXXXXXXXXXDDDDDDDNNNNNNNNNNNNNNNTLLLLLLLL +OJXXXJJLLLLKKVVVVVVVVVVVVFVSSSSSMVVVVVVMMMMMMMLLJJJJJJJJOOOOOQQRRRRRRRRRRRRRRRRRRRDDPPXXXXXXXXXXJXXXXXXXXXXXXXXXDDDDDNNNNNNNNNNNNNTTLLLLLLLL +OJXXXJJJLLKKWVVVVVVVVVVFFFSSSSSMMVZVVVVVMMMMMLLLJJJJJGGGOOOOQQQRWRRRRRRRRRRRRRRRRRRRPYXXXXXXXXXXJXXXXXXXXXXXXXXXDDDDDNNNNNNNNNNNNLLLLLLLLLLL +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PPPPPPPPIIIIIIIVVVVVVVVVVKKKKKKBBBBBBBBBBBBPBPPXXPPPXNNNNNNNNNNNOOOOOOOOOOOOOZZZZZTTTTTTT +HHHFFFHHFFFFVVVVVVVVVVVCCCCCCKKKKXNNNNNNNNNNNNNNPPPPPPPPPPIIIIIIIIIIVVIVVIIKKKKKKGGGBBBBBBBBBBPPPPXXXPNNNNNNNNNNNNNNOOOOOOOOOOZZZZZZZTTTTTTT +FFFFFFHHFFFFFFVVVVVVVVCCCCCKKKKKKKKNNNNNNNNNNNPPPPPPPPPPPPIIIIIIIIIIVIIIIIIIKKKKGGGGBBBBBBQBBBPPPPXXPPNNBBNNNNNNNNNNNNWOOOOOOOEEEZZZZTTTTTTT +FFFFFFFFFFFFFFFVVVVVVVCCCCKKKKKKKHKKKKWNNNNNNNPPPPPPIIIIIIIIIIIIIIIIIIIIIIIIKKKGGGGGBPPBHBQBBPPPPPPPPNNNBBNNNNNNNNNNNNOOOOOOOOOEEEZZZTTTTTTT diff --git a/solutions/solutions.cabal b/solutions/solutions.cabal index 5100eb0..c360865 100644 --- a/solutions/solutions.cabal +++ b/solutions/solutions.cabal @@ -1167,3 +1167,8 @@ executable sln_2024_11 import: day main-is: 2024/11.hs build-depends: containers + +executable sln_2024_12 + import: day + main-is: 2024/12.hs + build-depends: containers diff --git a/solutions/src/2024/12.hs b/solutions/src/2024/12.hs new file mode 100644 index 0000000..2d88afa --- /dev/null +++ b/solutions/src/2024/12.hs @@ -0,0 +1,55 @@ +{-# Language BlockArguments, ImportQualifiedPost, MonadComprehensions #-} +{-| +Module : Main +Description : Day 12 solution +Copyright : (c) Eric Mertens, 2024 +License : ISC +Maintainer : emertens@gmail.com + + + +-} +module Main (main) where + +import Advent (getInputMap, countBy) +import Advent.Coord (Coord, cardinal, above, right, below, left) +import Advent.Search (dfs) +import Data.List (unfoldr) +import Data.Map (Map) +import Data.Map qualified as Map +import Data.Set (Set) +import Data.Set qualified as Set + +-- | >>> :main +-- 1546338 +-- 978590 +main :: IO () +main = + do input <- getInputMap 2024 12 + let rs = regions input + print (sum (map (\x -> perimeter x * length x) rs)) + print (sum (map (\x -> walls x * length x) rs)) + +-- | Return a list of regions in the input map. +regions :: Map Coord Char -> [Set Coord] +regions = unfoldr \input -> + [ (region, Map.withoutKeys input region) + | (start, label) <- Map.lookupMin input + , let region = Set.fromList (dfs step start) + step i = [j | j <- cardinal i, Map.lookup j input == Just label] + ] + + +-- | Find the perimeter length of a region. +perimeter :: Set Coord -> Int +perimeter xs = length [() | x <- Set.toList xs, y <- cardinal x, y `Set.notMember` xs] + +-- | Compute the number of walls needed to surround a region by looking for +-- the corners of the region. +walls :: Set Coord -> Int +walls xs = + let f i = Set.member i xs in + countBy (\x -> not (f (above x)) && (not (f (right x)) || f (above (right x)))) xs + + countBy (\x -> not (f (below x)) && (not (f (right x)) || f (below (right x)))) xs + + countBy (\x -> not (f (right x)) && (not (f (above x)) || f (above (right x)))) xs + + countBy (\x -> not (f (left x)) && (not (f (above x)) || f (above (left x)))) xs \ No newline at end of file