Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Comparison by position and value

by ambrus (Abbot)
on Jan 02, 2005 at 11:21 UTC ( #418772=note: print w/replies, xml ) Need Help??


in reply to Comparison by position and value

sub compatible { my ($s1, $s2) = @_; $s1=~/\G_/gcs and $s2=~/./gcs or $s1=~/./gcs and $s2=~/\G_/gcs or return 0 until $s1=~/\G\z/ or $s2=~/\G\z/; 1; } print(compatible("_8__3__19", "4_8___7__") ? "true\n" : "false\n");

Update: this is wrong too, for the same reason as my other reply. Wait, I'll try to post a correction.

Update: Maybe this would work:

sub compatible { my ($s1, $s2) = @_; my $t; $s1=~/\G_/gcs and $s2=~/./gcs or $s1=~/(.)/gcs and $t = $1, $s2=~/\G_/gcs or $s2=~/(.)/gcs and +$t eq $1 or return 0 until $s1=~/\G\z/ or $s2=~/\G\z/; 1; } 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: this is wrong too.

Update:

sub compatible { my ($s1, $s2) = @_; my($c1, $c2, $d); { $s1 =~ /(.)/gs or return 1; $c1 = $1; $s2 =~ /(.)/gs or return 1; $c2 = $1; if ($c1 eq "_") { if ($c2 eq "_") { } else { vec($d, ord $c2, 1)++ and return; } } else { if ($c2 eq "_") { vec($d, ord $c1, 1)++ and return; } else { $c1 ne $c2 and return; vec($d, ord $c2, 1)++ + and return; } } redo; } } printf "%s v %s ? %s\n", @$_, compatible( @$_ ) || 0 for [ qw[ _8__3__19 48____7__ ] ], # compat [ qw[ _8__3__19 4_2___7__ ] ], # compat [ qw[ _8__3__19 4_8___7__ ] ], # clash [ qw[ __8_3__19 48____7__ ] ], # clash [ qw[ __8_3__19 84____7__ ] ], # clash [ qw[ _8__3__19 48_____7_ ] ]; # clash

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://418772]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2020-06-02 12:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (17 votes). Check out past polls.

    Notices?