Created
July 20, 2017 17:51
-
-
Save jimregan/24891acdcbc0a8566078ca2d7d14147b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
my @in = qw(asfalt asfaltu asfalcie); | |
sub longest_suffix { | |
my $list = shift; | |
my $first = shift(@{$list}); | |
for my $second(@in) { | |
my @a = split(//, $first); | |
my @b = split(//, $second); | |
my $len = ($#a < $#b) ? $#a : $#b; | |
my $common = ''; | |
for (my $i = 0; $i <= $len; $i++) { | |
if($a[$i] eq $b[$i]) { | |
$common .= $a[$i]; | |
} | |
} | |
$first = $common; | |
} | |
$first; | |
} | |
print longest_suffix(\@in); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment