note
johnnywang
Just tidy up what others have done, especially the non-closed situation.
<code>
use strict;
my @seg = (
[ 1, 1, 2, 1 ],
[ 5, 5, 1, 5 ],
[ 2, 3, 5, 3 ],
[ 5, 3, 5, 5 ],
[ 2, 1, 2, 3 ],
[ 1, 5, 1, 1 ]);
my %pairs = map{("[$_->[0],$_->[1]]","[$_->[2],$_->[3]]")} @seg;
my $start = "[1,1]";
my $current = $start;
do{
print $current,"\n";
$current = $pairs{$current};
}while(defined $pairs{$current} && $current ne $start)
__OUTPUT__
[1,1]
[2,1]
[2,3]
[5,3]
[5,5]
[1,5]
</code>
382584
382584