A1 Transcendence has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: SEEKING HELP
by GotToBTru (Prior) on Sep 30, 2015 at 12:16 UTC

    I would first write out the method you would use by hand and then try to turn sentences into code.

    Is this perchance homework? Because there is no need of math to solve it.

    Dum Spiro Spero
Re: SEEKING WISDOM
by u65 (Chaplain) on Sep 30, 2015 at 12:17 UTC

    First, you haven't taken the advice given to you on your previous post, i.e., you have not used strictures and warnings. Also, it would be helpful to put data enclosed by code blocks.

    I have a rough solution to your problem, but it doesn't show much since none of the data you've shown meet the criterion for keeping a summed pair. I'll post it (if no one else beats me to it) when I've cleaned it up a bit and added some new data.

    Update: correct typos and grammar at code block.

Re: SEEKING HELP
by AnomalousMonk (Archbishop) on Sep 30, 2015 at 14:44 UTC

    Assuming this is homework, and further to AnonyMonk's comment "This logic is akin to NXOR ie equality" above, consider the stringwise xor of two strings of equal length in which some characters at corresponding positions are the same and some are not.

    c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $m = ' 0 1 0 1'; my $p = ' 0 0 1 1'; ;; my $x = $m ^ $p; dd $x; " "\0\0\0\1\0\1\0\0"
    A  "\0" character (\000 octal, 0x00 hex) is produced in the resultant string at each position where the characters in the two input strings are the same. (Note that there are three different characters in the example input strings: space, '0' and '1'.) Something other than a  "\0" character is produced everywhere else.

    The resultant string can then be analyzed by a regex to pick out sequences of  "\0" characters that indicate regions of equality between the two input strings. This is the "traditional" way to quickly compare two strings of the same length for position-by-position | for regions of position-to-position equality/inequality. I would build my solution on this string-xor property: look for pairs of strings in which the ' 0 1 0 0 1 1' regions at the ends of each string are the same.

    Like u65, I have a solution that I am reluctant to post because of the homeworkish odor of the OP. Please show some more work, or convincing evidence that you are totally stuck for a way forward.

    Update: Clarification to this reply made in response to private query by GotToBTru.


    Give a man a fish:  <%-{-{-{-<

Re: SEEKING WISDOM
by Anonymous Monk on Sep 30, 2015 at 12:26 UTC

    Is this your homework?

    by adding the 0s and 1s ... keep ... strings that have 0s and 2s only, no 1s in the string.
    This logic is akin to NXOR ie equality. You effectively filter by exact (attributes) match. Do you really need to output "2"-s instead of "1"-s? Secondly, how would the "M" and "P" tags combine? As "MP", or should the tag be elided maybe?

Re: SEEKING HELP
by AnomalousMonk (Archbishop) on Oct 02, 2015 at 14:05 UTC

    Here's an approach to the problem of comparing records. Validity checking stub functions are included just as a suggestion of good practice; there are other ways of handling this. I notice that the  'HG00096.' section in each record pair always seems to be the same. If so, a check for this might be included in the
        m{ \A .{9} (?: \x00\x00){13} \z }xms
    regex, but I would prefer to do it in a separate validity check. If the initial sections of each pair up to and including the M/P character are guaranteed to be good, it's only necessary to check for equality of the tail section, e.g., with a
        m{ (?: \x00\x00){13} \z }xms
    regex.


    Give a man a fish:  <%-{-{-{-<

A reply falls below the community's threshold of quality. You may see it by logging in.