I'v tried to code it, without reading codes posted previously, just for enjoy. I'v been curious, how many rows it will has. O.K., it is not very perlish... Idea was very simple - zip the four arrays to one stream, fill circle buffer and test if last value of the buffer - 3 is equal to first value. Damn, 67 rows.
use strict; use warnings; my @a1 = ( 100, 204, 208, 312 ); my @a2 = ( 102, 313, 409 ); my @a3 = ( 205, 206, 315 ); my @a4 = ( 207, 210, 314 ); my $a = [\@a1,\@a2,\@a3,\@a4]; my @ai = (0, 0, 0, 0); my ($a1a2, $a3a4) = (getLess(0), getLess(2)); my @circle = (getNext(),getNext(),getNext()); my $ci = 3; while (defined($circle[$ci] = getNext())) { if ($circle[$ci][2]-3 == $circle[($ci+1)%4][2]) { for (my $i = 1; $i < 5; $i++) { print $circle[($ci+$i)%4][2]. ' ['.$circle[($ci+$i)%4][0].','.$circle[($ci+$i)%4][1].'] '; } print "\n"; } $ci = ($ci+1)%4; } sub getLess { my $offset = shift; my $ret; if (defined $$a[$offset][$ai[$offset]]) { if (defined $$a[$offset+1][$ai[$offset+1]]) { $offset++ if $$a[$offset][$ai[$offset]] > $$a[$offset+1][$ai[$ +offset+1]]; } $ret = [$offset, $ai[$offset], $$a[$offset][$ai[$offset]]]; $ai[$offset]++; } else { $offset++; if (defined $$a[$offset][$ai[$offset]]) { $ret = [$offset, $ai[$offset], $$a[$offset][$ai[$offset]]]; $ai[$offset]++; } } return $ret; } sub getNext { my $ret; if (defined $a1a2) { if (defined $a3a4) { if ($$a1a2[2] < $$a3a4[2]) { $ret = $a1a2; $a1a2 = getLess(0); } else { $ret = $a3a4; $a3a4 = getLess(2); } } else { $ret = $a1a2; $a1a2 = getLess(0); } } else { if (defined $a3a4) { $ret = $a3a4; $a3a4 = getLess(2); } } return $ret; }
updated: output is
204 [0,1] 205 [2,0] 206 [2,1] 207 [3,0] 205 [2,0] 206 [2,1] 207 [3,0] 208 [0,2] 312 [0,3] 313 [1,1] 314 [3,2] 315 [2,2]

In reply to Re^3: Searching parallel arrays. by pajout
in thread Searching parallel arrays. by BrowserUk

Title:
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, details, 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, summary, 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.