module Part2 where import Commons import Data.Char getCalibrationValueLeft :: CalibrationLine -> Char getCalibrationValueLeft ('o': 'n': 'e': _) = '1' getCalibrationValueLeft ('t': 'w': 'o': _) = '2' getCalibrationValueLeft ('t': 'h': 'r': 'e': 'e': _) = '3' getCalibrationValueLeft ('f': 'o': 'u': 'r': _) = '4' getCalibrationValueLeft ('f': 'i': 'v': 'e': _) = '5' 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: _) | isDigit h = h getCalibrationValueLeft (_: t) = getCalibrationValueLeft t getCalibrationValueRight :: CalibrationLine -> Char getCalibrationValueRight ('e': 'n': 'o': _) = '1' getCalibrationValueRight ('o': 'w': 't': _) = '2' getCalibrationValueRight ('e': 'e': 'r': 'h': 't': _) = '3' getCalibrationValueRight ('r': 'u': 'o': 'f': _) = '4' getCalibrationValueRight ('e': 'v': 'i': 'f': _) = '5' 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: _) | isDigit h = h getCalibrationValueRight (_: t) = getCalibrationValueRight t getCalibrationValue :: CalibrationLine -> Integer getCalibrationValue line = read [getCalibrationValueLeft line, getCalibrationValueRight (reverse line)] getCalibrationValues :: CalibrationDocument -> [Integer] getCalibrationValues [h] = [getCalibrationValue h] getCalibrationValues (h: t) = getCalibrationValue h: getCalibrationValues t