Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: reordering segments to form a polygon

by Jaap (Curate)
on Aug 13, 2004 at 10:06 UTC ( #382594=note: print w/replies, xml ) Need Help??


in reply to reordering segments to form a polygon

I guess this would be the hash approach you speak of:
#!/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"; }
Output:
1,1 2,1 2,3 5,3 5,5 1,5

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://382594]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2022-11-26 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?