in reply to match diagonal text

From the above matrix i need to find diagonal 1111 or 2222.

Do you mean that you are only interested in exactly 4 (not say 3) of '1's or '2's on a diagonal?

Are you only interested in those on this \ diagonal and not this / one?

Will the input always be 6 x 4?

If the answers to those three are yes, then a simple regex may be all you need:

print $_, "\n", m[([12])(?:.{7}\1){3}]s ? 'matched' : 'failed' for $a, $b, $c, $d;; 220021 000200 020222 020222 failed 100000 010000 001000 000100 matched 102000 010200 001020 000102 matched 102000 010200 001020 000201 failed

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: match diagonal text
by arivu198314 (Sexton) on Sep 22, 2011 at 09:11 UTC

    Thanks for your reply, please find my answers here

    1. Do you mean that you are only interested in exactly 4 (not say 3) of '1's or '2's on a diagonal? Yes

    2. Are you only interested in those on this \ diagonal and not this / one? Yes i need both diagonals

    3. Will the input always be 6 x 4? not always, it will vary.

    Please let me know for further assistance

      Will the input always be 6 x 4? not always, it will vary.

      Over what range?

      Please let me know for further assistance

      Thank you.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        While you're at it, BrowserUK, I'd like a pony.

        ~ 500x50