main
Yanick Champoux 2018-12-02 11:40:38 -05:00
parent 9d40efda2b
commit 8ecca99278
1 changed files with 39 additions and 0 deletions

39
2018/02/sol2.pl Normal file
View File

@ -0,0 +1,39 @@
use 5.20.0;
use warnings;
my @items = <>;
use List::AllUtils qw/ pairwise /;
use experimental qw/
signatures
postderef
current_sub
/;
while( my $next = shift @items ) {
my $match = find([ split '', $next], @items) or next;
say $match;
last;
}
sub find( $next, @items ) {
my $contender = splice @_, 1, 1 or return;
$contender = [ split '', $contender ];
my $diff = 0;
my $r = '';
for my $i ( 0..$next->@* ) {
if ( $next->[$i] eq $contender->[$i] ) {
$r .= $next->[$i];
}
else {
last if $diff++;
}
}
return $r if $diff == 1;
goto __SUB__;
}