in reply to Re^2: Link Connectivity Algorithim
in thread Link Connectivity Algorithim
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.
|
|---|