Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How can sets be recursively concatenated when intersecting with each other

by jdporter (Paladin)
on Apr 25, 2011 at 06:44 UTC ( [id://901155]=note: print w/replies, xml ) Need Help??


in reply to How can sets be recursively concatenated when intersecting with each other

use Graphs.

use Graph; use strict; use warnings; my @sets = ( [qw(0)], [qw(0 1)], [qw(0 1 2)], [qw(1 2 3)], [qw(4 5 6)], ); my $gr = new Graph undirected => 1, unionfind => 1; for my $set ( @sets ) { @$set == 1 and $gr->add_vertex( $set->[0] ); @$set <= 1 and next; $gr->add_edge( $set->[$_-1], $set->[$_] ) for 1 .. $#{$set}; } for my $set ( $gr->connected_components ) { print "( @$set )\n"; }
I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.
  • Comment on Re: How can sets be recursively concatenated when intersecting with each other
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-19 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found