Longest palindromic substrings: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (→{{header|Raku}}: Show longest 5 substring groups. Minor edits) |
|||
Line 445: | Line 445: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
{{works with|Rakudo|2020.09}} |
{{works with|Rakudo|2020.09}} |
||
This version regularizes (ignores) case and ignores non |
This version regularizes (ignores) case and ignores non alphanumeric characters. It is only concerned with finding the ''longest'' palindromic substrings so does not exhaustively find ''all possible'' palindromes. If a palindromic substring is found to be part of a longer palindrome, it is not captured separately. Showing the longest 5 palindromic substring groups. |
||
<lang perl6>my @chars = q:to/END/ .lc.comb: /\w/; |
<lang perl6>my @chars = q:to/END/ .lc.comb: /\w/; |
||
Line 508: | Line 508: | ||
} |
} |
||
.unique.sort.put for @cpfoa.grep( *.so ).tail;</lang> |
.unique.sort.put for @cpfoa.grep( *.so ).tail(5).reverse;</lang> |
||
{{out}} |
{{out}} |
||
<pre>doninemeninterpretninemeninod godarednuggetafateggunderadog |
<pre>doninemeninterpretninemeninod godarednuggetafateggunderadog |
||
gohangasalamiimalasagnahog |
|||
arwontloversrevoltnowra |
|||
imanamregalagermanami mayamoodybabydoomayam ootnolemonsnomelontoo oozyratinasanitaryzoo |
|||
ratsliveonnoevilstar</pre> |
|||
This isn't particularly optimised but isn't too shabby either. When run against the first million digits of pi: [http://www.eveandersson.com/pi/digits/1000000 http://www.eveandersson.com/pi/digits/1000000] |
This isn't particularly optimised but isn't too shabby either. When run against the first million digits of pi: [http://www.eveandersson.com/pi/digits/1000000 http://www.eveandersson.com/pi/digits/1000000] we get: |
||
<pre>9475082805749 |
<pre>9475082805749 |