Longest palindromic substrings: Difference between revisions

Content added Content deleted
m (→‎{{header|Haskell}}: Tidied some if then else away)
Line 94: Line 94:


<lang haskell>-------------- LONGEST PALINDROMIC SUBSTRINGS ------------
<lang haskell>-------------- LONGEST PALINDROMIC SUBSTRINGS ------------

longestPalindromes :: String -> ([String], Int)
longestPalindromes :: String -> ([String], Int)
longestPalindromes s = go $ palindromes s
longestPalindromes s = go $ palindromes s
Line 112: Line 111:


palindromicNuclei :: String -> [(String, (String, String))]
palindromicNuclei :: String -> [(String, (String, String))]
palindromicNuclei s = contexts >>= go
palindromicNuclei =
concatMap go .
init . tail . ((zip . scanl (flip ((<>) . return)) []) <*> scanr (:) [])
where
where
contexts = (init . tail) (zip prefixes suffixes)
prefixes = scanl (flip ((<>) . return)) [] s
suffixes = scanr (:) [] s
go (a@(x:_), b@(h:y:ys)) =
go (a@(x:_), b@(h:y:ys)) =
if x == h
if x == h