1
0
Fork 0

Trying some overlap logic in Day 1

Bill Ewanick 2023-12-02 13:38:22 -05:00
parent 2005e169f4
commit 4b0d2758a8
1 changed files with 26 additions and 0 deletions

View File

@ -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]