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

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":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (4)
    As of 2021-01-23 08:53 GMT
    Find Nodes?
      Voting Booth?