diff --git a/src/advent_of_code/2023/1.hs b/src/advent_of_code/2023/1.hs index 6742a06..480ef7b 100644 --- a/src/advent_of_code/2023/1.hs +++ b/src/advent_of_code/2023/1.hs @@ -88,6 +88,32 @@ isNumP2 = flip elem (numberChars ++ numberWords) numberWords :: [String] numberWords = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"] +overlapsSpec :: [(String, String)] +overlapsSpec = + [ ("zero" , "one" ) + , ("one" , "eight") + , ("two" , "one" ) + , ("three", "eight") + , ("five" , "eight") + , ("seven", "nine" ) + , ("eight", "two" ) + , ("eight", "three") + , ("nine" , "eight") + ] + +overlapsDerived :: [(String, [String])] +overlapsDerived = zip numberWords $ map findOverlaps numberWords + +findOverlaps :: String -> [String] +findOverlaps str = filter (\s -> last str == head s) numberWords + +combineOverlaps :: (String, [String]) -> [String] +combineOverlaps (numStr, [] ) = [] +combineOverlaps (numStr, over:laps) = (numStr ++ tail over) : combineOverlaps (numStr, laps) + +overlaps :: [String] +overlaps = filter (/= "") $ concatMap combineOverlaps overlapsDerived + numberChars :: [String] numberChars = map show [0..9]