Files
advent-of-code-2023/day01/Part1.hs
2023-12-04 19:05:20 +01:00

17 lines
562 B
Haskell

module Part1 where
import Commons
import Data.Char (isDigit)
getCalibrationValuePart :: CalibrationLine -> Char
getCalibrationValuePart (h: _) | isDigit h = h
getCalibrationValuePart (_: t) = getCalibrationValuePart t
getCalibrationValue :: CalibrationLine -> Integer
getCalibrationValue line = read [getCalibrationValuePart line, getCalibrationValuePart . reverse $ line]
getCalibrationValues :: CalibrationDocument -> [Integer]
getCalibrationValues [h] = [getCalibrationValue h]
getCalibrationValues (h: t) = getCalibrationValue h: getCalibrationValues t