note
Jaap
I guess this would be the hash approach you speak of:
<code>
#!/cadappl/bin/perl -w -Ilib
use strict;
use Data::Dumper;
my @r = (
[ 5, 3, 5, 5 ],
[ 1, 1, 2, 1 ],
[ 2, 1, 2, 3 ],
[ 5, 5, 1, 5 ],
[ 1, 5, 1, 1 ],
[ 2, 3, 5, 3 ]
);
my %lineTo;
foreach my $ref (@r)
{
$lineTo{"$$ref[0],$$ref[1]"} = "$$ref[2],$$ref[3]";
}
my $start = "1,1";
my $curr = $start;
print "$curr\n";
while (($curr = $lineTo{$curr}) ne $start)
{
print "$curr\n";
}
</code>
Output:
<code>
1,1
2,1
2,3
5,3
5,5
1,5
</code>
382584
382584