Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: reordering segments to form a polygon

by Jaap (Curate)
on Aug 13, 2004 at 10:06 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (8)
As of 2024-04-18 21:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found