Trying some overlap logic in Day 1
parent
2005e169f4
commit
4b0d2758a8
|
@ -88,6 +88,32 @@ isNumP2 = flip elem (numberChars ++ numberWords)
|
||||||
numberWords :: [String]
|
numberWords :: [String]
|
||||||
numberWords = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
|
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 :: [String]
|
||||||
numberChars = map show [0..9]
|
numberChars = map show [0..9]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue