module Part2 where import Commons 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: _) | h >= '0' && h <= '9' = 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: _) | h >= '0' && h <= '9' = 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))