Longest palindromic substrings: Difference between revisions

→‎{{header|Raku}}: Add concurrency, useless for default, cuts pi digit time by nearly half
m (→‎Phix: as per recent Raku mod, skip the s[i]=s[i] test)
(→‎{{header|Raku}}: Add concurrency, useless for default, cuts pi digit time by nearly half)
Line 620:
#"
 
my @cpfoa; = flat
(1 ..^ @chars).race(:1000batch).map: -> \idx {
 
my int $i = 1my @s;
 
loop {
last if $i >= @chars;
for 1, 2 {
my int ($rev, $fwd) = $_, 1;
loop {
quietly last if ($rev > $i) || (($i + $fwd) == @charsidx) || (@chars[$iidx - $rev] ne @chars[$iidx + $fwd]);
$rev = $rev + 1;
$fwd = $fwd + 1;
}
@cpfoa[(my $pal =s.push: @chars[$iidx - $rev ^..^ $iidx + $fwd].join).chars].push: $pal if $rev + $fwd > 2;
last if @chars[$iidx - 1] ne @chars[$iidx];
}
$inext = $iunless + 1@s;
@s
}
 
"{.[0].charskey} ({+$_.value})\t{.value.unique.sort}".put for @cpfoa.grepclassify( *.sochars ).tailsort(5 -*.key ).reversehead(5);</lang>
{{out}}
Returns the length, (the count) and the list:
Line 649 ⟶ 647:
</pre>
 
This isn't intensively optimised but isn't too shabby either. When run against the first million digits of pi: [httphttps://www.eveanderssongithub.com/pithundergnat/digitsrc/1000000 http:blob/master/www.eveandersson.comresouces/pi/.txt 1000000 digits/1000000 of pi text file] (Pass in the file path/name at the command line) we get:
 
<pre>13 (1) 9475082805749
Line 656 ⟶ 654:
10 (9) 0045445400 0136776310 1112552111 3517997153 5783993875 6282662826 7046006407 7264994627 8890770988
9 (98) 019161910 020141020 023181320 036646630 037101730 037585730 065363560 068363860 087191780 091747190 100353001 104848401 111262111 131838131 132161231 156393651 160929061 166717661 182232281 193131391 193505391 207060702 211878112 222737222 223404322 242424242 250171052 258232852 267919762 272636272 302474203 313989313 314151413 314424413 318272813 323212323 330626033 332525233 336474633 355575553 357979753 365949563 398989893 407959704 408616804 448767844 450909054 463202364 469797964 479797974 480363084 489696984 490797094 532121235 546000645 549161945 557040755 559555955 563040365 563828365 598292895 621969126 623707326 636414636 636888636 641949146 650272056 662292266 667252766 681565186 684777486 712383217 720565027 726868627 762727267 769646967 777474777 807161708 819686918 833303338 834363438 858838858 866292668 886181688 895505598 896848698 909565909 918888819 926676629 927202729 929373929 944525449 944848449 953252359 972464279 975595579 979202979 992868299</pre>
in slightlyright morearound than 127 seconds on my system.
 
=={{header|REXX}}==
10,333

edits