Your question reminds me of the joke about the engineer and the mathematician who are asked for an algorithm to boil a pot of water.  They both say:

  1. Fill pot with water
  2. Carry pot to stove
  3. Light stove
  4. Wait for pot to boil

Then they are asked for an algorithm for boiling a pot which already contains water.

The engineer simply replies with steps 2-4 above.

The mathematician replies:  "Step one = pour out the water.  Now the problem is reduced to the same as the first!"

My simplistic answer would be to take your array and convert it to pairs (using a hash along the way):

my @T1 = ( 'a|b|c', 'c|d', 'j|k|l|m', 'm|n|o', 'o|p|q|r|s' ); my %newT1; foreach (@T1) { my @points = split /\|/; for (my $i = 1; $i < @points; $i++) { my $link = $points[$i-1] . '|' . $points[$i]; $newT1{$link}++; } } my @newT1 = keys %newT1; # Verify that the new array contains the desired points printf "\@newT1 = %s\n", Dumper(\@newT1);

Now the problem's been reduced to the first one.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Re^3: Link Connectivity Algorithim by liverpole
in thread Link Connectivity Algorithim by dunkirk_phil

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.