#!/usr/bin/perl
use 5.016;
use warnings;
use List
::Util qw(reduce first
); use Data::Dumper;
local $Data::Dumper::Terse = 1; local $Data::Dumper::Indent = 0;
sub f {
@{
+reduce{
my $x = first{ $a->[$_] == $b } (0 .. $#{$a});
defined $x ? [@{$a}[0 .. $x - 1, $x + 1 .. $#{$a}]] : $a; } [@{$_[0]}], @{$_[1]}
} == 1
}
foreach(
[[1,2,3],[5,6,7]],
[[1,1,1],[1,1,2]],
[[1,1,2],[2,2,1]],
[[9,8,9],[8,6,4]],
[[9,7,2],[2,2,9]],
){
say Dumper($_), " => ", (f(@{$_}) ? "true" : "false");
}
IyEvdXNyL2Jpbi9wZXJsCnVzZSA1LjAxNjsKdXNlIHdhcm5pbmdzOwpubyB3YXJuaW5ncyBxdyhvbmNlKTsKdXNlIExpc3Q6OlV0aWwgcXcocmVkdWNlIGZpcnN0KTsKdXNlIERhdGE6OkR1bXBlcjsKbG9jYWwgJERhdGE6OkR1bXBlcjo6VGVyc2UgPSAxOwpsb2NhbCAkRGF0YTo6RHVtcGVyOjpJbmRlbnQgPSAwOwoKc3ViIGYgewoJQHsKCQkrcmVkdWNlewoJCQlteSAkeCA9IGZpcnN0eyAkYS0+WyRfXSA9PSAkYiB9ICgwIC4uICQjeyRhfSk7CgkJCWRlZmluZWQgJHggPyBbQHskYX1bMCAuLiAkeCAtIDEsICR4ICsgMSAuLiAkI3skYX1dXSA6ICRhOwoJCX0gW0B7JF9bMF19XSwgQHskX1sxXX0KCX0gPT0gMQp9Cgpmb3JlYWNoKAoJW1sxLDIsM10sWzUsNiw3XV0sCglbWzEsMSwxXSxbMSwxLDJdXSwKCVtbMSwxLDJdLFsyLDIsMV1dLAoJW1s5LDgsOV0sWzgsNiw0XV0sCglbWzksNywyXSxbMiwyLDldXSwKKXsKCXNheSBEdW1wZXIoJF8pLCAiID0+ICIsIChmKEB7JF99KSA/ICJ0cnVlIiA6ICJmYWxzZSIpOwp9Cg==
[[1,2,3],[5,6,7]] => false
[[1,1,1],[1,1,2]] => true
[[1,1,2],[2,2,1]] => true
[[9,8,9],[8,6,4]] => false
[[9,7,2],[2,2,9]] => true