It took me the afternoon but I got a LSP working

This commit is contained in:
2023-12-02 16:16:57 +01:00
parent a36a4ccbe9
commit eedd910d67
8 changed files with 35 additions and 31 deletions

View File

@@ -1,6 +1,8 @@
module Part2 where
import Commons
import Data.Char
getCalibrationValueLeft :: CalibrationLine -> Char
getCalibrationValueLeft ('o': 'n': 'e': _) = '1'
@@ -12,7 +14,7 @@ getCalibrationValueLeft ('s': 'i': 'x': _) = '6'
getCalibrationValueLeft ('s': 'e': 'v': 'e': 'n': _) = '7'
getCalibrationValueLeft ('e': 'i': 'g': 'h': 't': _) = '8'
getCalibrationValueLeft ('n': 'i': 'n': 'e': _) = '9'
getCalibrationValueLeft (h: _) | h >= '0' && h <= '9' = h
getCalibrationValueLeft (h: _) | isDigit h = h
getCalibrationValueLeft (_: t) = getCalibrationValueLeft t
getCalibrationValueRight :: CalibrationLine -> Char
@@ -25,12 +27,12 @@ getCalibrationValueRight ('x': 'i': 's': _) = '6'
getCalibrationValueRight ('n': 'e': 'v': 'e': 's': _) = '7'
getCalibrationValueRight ('t': 'h': 'g': 'i': 'e': _) = '8'
getCalibrationValueRight ('e': 'n': 'i': 'n': _) = '9'
getCalibrationValueRight (h: _) | h >= '0' && h <= '9' = h
getCalibrationValueRight (h: _) | isDigit h = h
getCalibrationValueRight (_: t) = getCalibrationValueRight t
getCalibrationValue :: CalibrationLine -> Integer
getCalibrationValue line = read [(getCalibrationValueLeft line), (getCalibrationValueRight (reverse line))]
getCalibrationValue line = read [getCalibrationValueLeft line, getCalibrationValueRight (reverse line)]
getCalibrationValues :: CalibrationDocument -> [Integer]
getCalibrationValues (h: []) = [(getCalibrationValue h)]
getCalibrationValues (h: t) = ((getCalibrationValue h): (getCalibrationValues t))
getCalibrationValues [h] = [getCalibrationValue h]
getCalibrationValues (h: t) = getCalibrationValue h: getCalibrationValues t