Longest palindromic substrings: Difference between revisions
Content deleted Content added
m →{{header|REXX}}: shortened a long statement (line), add/changed comments and whitespace. |
Alextretyak (talk | contribs) Added 11l |
||
Line 9:
{{Template:Strings}}
<br><br>
=={{header|11l}}==
<lang 11l>F longest_palindrome(s)
V t = Array(‘^’s‘$’).join(‘#’)
V n = t.len
V p = [0] * n
V c = 0
V r = 0
L(i) 1 .< n - 1
p[i] = (r > i) & min(r - i, p[2 * c - i]) != 0
L t[i + 1 + p[i]] == t[i - 1 - p[i]]
p[i]++
I i + p[i] > r
(c, r) = (i, i + p[i])
V (max_len, center_index) = max(enumerate(p).map((i, n) -> (n, i)))
R s[(center_index - max_len) I/ 2 .< (center_index + max_len) I/ 2]
L(s) [‘three old rotators’,
‘never reverse’,
‘stable was I ere I saw elbatrosses’,
‘abracadabra’,
‘drome’,
‘the abbatial palace’]
print(‘'’s‘' -> '’longest_palindrome(s)‘'’)</lang>
{{out}}
<pre>
'three old rotators' -> 'rotator'
'never reverse' -> 'ever reve'
'stable was I ere I saw elbatrosses' -> 'table was I ere I saw elbat'
'abracadabra' -> 'ada'
'drome' -> 'e'
'the abbatial palace' -> 'abba'
</pre>
=={{header|F_Sharp|F#}}==
|