Longest palindromic substrings: Difference between revisions
Content added Content deleted
Line 385: | Line 385: | ||
the given string, tupled with the |
the given string, tupled with the |
||
maximal length. |
maximal length. |
||
Non |
Non-alphanumerics are included here. |
||
''' |
''' |
||
k = s.lower() |
k = s.lower() |
||
Line 400: | Line 400: | ||
] if palindromes else list(s), |
] if palindromes else list(s), |
||
maxLength |
maxLength |
||
) |
) if s else ([], 0) |
||
Line 429: | Line 429: | ||
iEnd = len(s) - 1 |
iEnd = len(s) - 1 |
||
def |
def limit(ij): |
||
i, j = ij |
i, j = ij |
||
return 0 == i or iEnd == j or s[i-1] != s[j+1] |
return 0 == i or iEnd == j or s[i-1] != s[j+1] |
||
Line 438: | Line 438: | ||
def go(ij): |
def go(ij): |
||
ab = until( |
ab = until(limit)(expansion)(ij) |
||
return s[ab[0]:ab[1] + 1] |
return s[ab[0]:ab[1] + 1] |
||
return go |
return go |
||
Line 456: | Line 456: | ||
'abracadabra', |
'abracadabra', |
||
'drome', |
'drome', |
||
'abbatial palace' |
'the abbatial palace', |
||
'' |
|||
]) |
]) |
||
) |
) |
||
Line 517: | Line 518: | ||
'abracadabra' -> (['aca', 'ada'], 3) |
'abracadabra' -> (['aca', 'ada'], 3) |
||
'drome' -> (['d', 'r', 'o', 'm', 'e'], 1) |
'drome' -> (['d', 'r', 'o', 'm', 'e'], 1) |
||
'the abbatial palace' -> (['abba'], 4) |
|||
'' -> ([], 0)</pre> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |