2024 Day 03 in Haskell

This commit is contained in:
germax26 2024-12-04 18:43:42 +11:00
parent f298b13537
commit e27b9f9b3b
Signed by: germax26
SSH Key Fingerprint: SHA256:N3w+8798IMWBt7SYH8G1C0iJlIa2HIIcRCXwILT5FvM

14
2024/day03/day03.hs Normal file
View File

@ -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