From e27b9f9b3b6555aad89e3693338f0a73c29b265a Mon Sep 17 00:00:00 2001 From: germax26 Date: Wed, 4 Dec 2024 18:43:42 +1100 Subject: [PATCH] 2024 Day 03 in Haskell --- 2024/day03/day03.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 2024/day03/day03.hs diff --git a/2024/day03/day03.hs b/2024/day03/day03.hs new file mode 100644 index 0000000..315eba6 --- /dev/null +++ b/2024/day03/day03.hs @@ -0,0 +1,14 @@ +{-# OPTIONS_GHC -Wno-x-partial #-} + +import Aoc +import Text.Regex.PCRE +import Data.List.Split ( splitOn ) + +part1 :: [String] -> Int +part1 = sum . map (sum . map (product . map read . tail) . (=~ "mul\\((\\d+),(\\d+)\\)")) + +part2 :: [String] -> Int +part2 = part1 . map (head . splitOn "don't()") . splitOn "do()" . concat + +main :: IO () +main = aocMain id part1 part2 \ No newline at end of file