RosettaCodeData/Task/Longest-common-substring/Raku/longest-common-substring-2.raku
2023-07-01 13:44:08 -04:00

6 lines
362 B
Raku

sub substrings ($s) { (flat (0..$_ X 1..$_).grep:{$_ [+] @_}).map: { $s.substr($^a, $^b) } given $s.chars }
sub infix:<LCS>($s1, $s2) { ([] ($s1, $s2)».&substrings).keys.sort(*.chars).tail }
my $first = 'thisisatest';
my $second = 'testing123testing';
say "The longest common substring between '$first' and '$second' is '{$first LCS $second}'.";