diff --git a/adventofcode2025.cabal b/adventofcode2025.cabal index 0bef9e9..51426f9 100644 --- a/adventofcode2025.cabal +++ b/adventofcode2025.cabal @@ -39,3 +39,4 @@ executable adventofcode2025 Day06 Day07 Day08 + Day09 diff --git a/src/Day09.hs b/src/Day09.hs new file mode 100644 index 0000000..a458102 --- /dev/null +++ b/src/Day09.hs @@ -0,0 +1,33 @@ +{-# OPTIONS_GHC -Wno-incomplete-patterns #-} + +module Day09 + ( day09_1, + ) +where + +import Data.List.Split (splitOn) + +type Point = (Int, Int) + +readPoint :: [String] -> Point +readPoint (x : y : _) = (read x, read y) + +area :: Point -> Point -> Int +area (x1, y1) (x2, y2) = abs (x2 - x1 + 1) * abs (y2 - y1 + 1) + +getMaxArea :: [Point] -> Int +getMaxArea vertices = maximum $ [area x y | x <- vertices, y <- vertices, x /= y] + +parseInput :: IO [Point] +parseInput = do + input <- lines <$> readFile "input/day9.txt" + let points = map (readPoint . splitOn ",") input + return points + +day09_1 :: IO () +day09_1 = do + vertices <- parseInput + let result = getMaxArea vertices + putStrLn $ + "Day 9, Puzzle 1 solution: " + ++ show result diff --git a/src/Main.hs b/src/Main.hs index 4eab540..531ddf1 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -8,6 +8,7 @@ import Day05 (day05_1, day05_2) import Day06 (day06_1, day06_2) import Day07 (day07_1) import Day08 (day08_1, day08_2) +import Day09 (day09_1) import System.Environment (getArgs) main :: IO () @@ -52,6 +53,9 @@ main = do "8" : _ -> do day08_1 day08_2 + "9" : "1" : _ -> day09_1 + "9" : _ -> do + day09_1 "all" : _ -> do day01_1 day01_2 @@ -68,4 +72,5 @@ main = do day07_1 day08_1 day08_2 + day09_1 _ -> error "Not implemented"