Longest palindromic substrings: Difference between revisions

(Added solution for Action!)
Line 448:
"the abbatial palace" -> (["abba"],4)
"" -> ([],0)</pre>
 
=={{header|jq}}==
'''Adapted from [[#Wren]]'''
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<lang jq>def longestPalindromicSubstring:
length as $len
| if $len <= 1 then .
else explode as $s
| {targetLen: $len, longest: [], i: 0}
| until(.stop;
(.i + .targetLen - 1) as $j
| if $j < $len
then $s[.i:$j+1] as $ss
| if $ss == ($ss|reverse) then .longest += [$ss] else . end
| .i += 1
else
if .longest|length > 0 then .stop=true else . end
| .i = 0
| .targetLen += - 1
end )
| .longest
| map(implode)
| unique
end ;
def strings:
["babaccd", "rotator", "reverse", "forever", "several", "palindrome", "abaracadaraba"];
 
"The palindromic substrings having the longest length are:",
(strings[]
| longestPalindromicSubstring as $longest
| " \(.): length \($longest[0]|length) -> \($longest)"
)</lang>
 
{{out}}
<pre>
The palindromic substrings having the longest length are:
babaccd: length 3 -> ["aba","bab"]
rotator: length 7 -> ["rotator"]
reverse: length 5 -> ["rever"]
forever: length 5 -> ["rever"]
several: length 3 -> ["eve"]
palindrome: length 1 -> ["a","d","e","i","l","m","n","o","p","r"]
abaracadaraba: length 3 -> ["aba","aca","ada","ara"]
</pre>
 
 
=={{header|Julia}}==
2,442

edits