Add Day 3, Puzzle 1 solution

This commit is contained in:
Daniele Fucini
2025-12-03 20:20:07 +01:00
parent 32687cdfdd
commit c93dbadb5a
3 changed files with 31 additions and 0 deletions

View File

@@ -32,3 +32,4 @@ executable adventofcode2025
other-modules: other-modules:
Day01 Day01
Day02 Day02
Day03

25
src/Day03.hs Normal file
View File

@@ -0,0 +1,25 @@
module Day03
( day03_1,
)
where
getBankJoltage :: String -> Int
getBankJoltage bank = read [x, y]
where x = maximum $ init bank
y = maximum bank'
bank' = drop 1 $ dropWhile (/= x) bank
getTotalJoltage :: [String] -> Int
getTotalJoltage banks = sum $ map getBankJoltage banks
parseInput :: IO [String]
parseInput = do
lines <$> readFile "input/day3.txt"
day03_1 :: IO ()
day03_1 = do
banks <- parseInput
let joltage = getTotalJoltage banks
putStrLn $
"Day 3, Puzzle 1 solution: "
++ show joltage

View File

@@ -2,6 +2,7 @@ module Main (main) where
import Day01 (day01_1, day01_2) import Day01 (day01_1, day01_2)
import Day02 (day02_1, day02_2) import Day02 (day02_1, day02_2)
import Day03 (day03_1)
import System.Environment (getArgs) import System.Environment (getArgs)
main :: IO () main :: IO ()
@@ -18,9 +19,13 @@ main = do
"2" : _ -> do "2" : _ -> do
day02_1 day02_1
day02_2 day02_2
"3" : "1" : _ -> day03_1
"3" : _ -> do
day03_1
"all" : _ -> do "all" : _ -> do
day01_1 day01_1
day01_2 day01_2
day02_1 day02_1
day02_2 day02_2
day03_1
_ -> error "Not implemented" _ -> error "Not implemented"