sub compatible {
my ($s1, $s2) = @_;
y/_/\0/c for $s1, $s2;
!(($s1 | $s2)=~y/\0//);
}
print(compatible("_8__3__19", "48_____7_") ? "true\n" : "false\n");
Update:
BrowserUK has pointed out that this is wrong. Indeed, it does not work if there is
the same digit in both positions of the same string.
Update: Corrected (I hope) code
sub compatible {
y/_/\477/c, y/_/\0/ for my @m = @_;
!((($_[0] ^ $_[1]) & $m[0] & $m[1]) =~ y/\0//c);
}
printf "%s v %s ? %s\n", @$_, compatible( @$_ ) ? 1 : 0
for [ qw[ _8__3__19 48____7__ ] ], # compat
[ qw[ _8__3__19 4_8___7__ ] ], # compat
[ qw[ _8__3__19 48_____7_ ] ]; # clash
Update: Oh, I've got it wrong again. forget this.