part 2
This commit is contained in:
parent
9d40efda2b
commit
8ecca99278
39
2018/02/sol2.pl
Normal file
39
2018/02/sol2.pl
Normal 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__;
|
||||
}
|
Loading…
Reference in New Issue
Block a user