Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Comparison by position and value

by BrowserUk (Patriarch)
on Jan 02, 2005 at 11:21 UTC ( [id://418773]=note: print w/replies, xml ) Need Help??


in reply to Re: Comparison by position and value
in thread Comparison by position and value

That doesn't work as is?

#! perl -slw use strict; sub compatible { my ($s1, $s2) = @_; y/_/\0/c for $s1, $s2; !(($s1 | $s2)=~y/\0//); } printf "%s v %s ? %s\n", @$_, compatible( @$_ ) ? 1 : 0 for [ qw[ _8__3__19 48____7__ ] ], # good [ qw[ _8__3__19 4_8___7__ ] ], # bad [ qw[ _8__3__19 48_____7_ ] ]; # bad __END__ [11:18:29.65] P:\test>test _8__3__19 v 48____7__ ? 0 _8__3__19 v 4_8___7__ ? 1 _8__3__19 v 48_____7_ ? 0

Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.

Replies are listed 'Best First'.
Re^3: Comparison by position and value
by ambrus (Abbot) on Jan 02, 2005 at 11:25 UTC

    I don't see your problem:

    _8__3__19 v 48____7__ ? 0 ^ _8__3__19 v 4_8___7__ ? 1 _8__3__19 v 48_____7_ ? 0 ^ ^

    For these strings at least, the result is 0 iff there is a clash of two digits somewhere.

      The first two strings are compatible, because they only overlap (contain a digit in the same place) where the digit is the same in both strings. Please see the 3 examples in the OP.


      Examine what is said, not who speaks.
      Silence betokens consent.
      Love the truth but pardon error.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-04-23 15:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found