Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Given two strings of equal length that contain digits and some placeholder value, I want a fast way to determine if the pair are 'compatible'.

Eg. Given (where underscore represents the placeholder but this could be substituted by any other non-digit value that helped the algorithm)

_8__3__19 48____7__

These two strings are compatible because no single digit appears in both strings except where it appears in the same position (8)

Whereas these two would be incompatible

_8__3__19 4_8___7__

because the digit 8 appears in both, but at a different position. And these two are incompatible

_8__3__19 48_____7_

because the second last digit in both strings contains a different value.

I know how to do this with a loop and substr and a hash, but it is rather slow and I have a set N of M sets of these strings and I want to produce a set P, where each element of P is a string that is combines one string from as many of the N sets of strings as are compatible. Given the combinatorial nature of the problem, I need to make it as quick as possible.

I keep thinking that this can be done using string-wise boolean operations, but I cannot see how?

If there is a better way of structuring the data (eg. arrays of char rather than strings) that makes the process quicker or easier that's good to.

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

In reply to Comparison by position and value by BrowserUk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2023-10-05 00:21 GMT
Find Nodes?
    Voting Booth?

    No recent polls found