in reply to Building Networks of Matches
#!/usr/bin/perl -w use strict; use Graph::Undirected; my $graph = Graph::Undirected->new(); my @data = map { [ grep defined, split /\s+/ ] } <DATA>; foreach my $line ( 1 .. scalar @data ) { $graph->add_edges( map { $line => $_ } @{ $data[ $line - 1 ] } ) } my @sets = $graph->strongly_connected_components; for (@sets) { printf "{ %s }\n", join ' ', sort { $a cmp $b } @$_; } __END__ a b c d e f b g h i j k l m f
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Building Networks of Matches
by osunderdog (Deacon) on Dec 23, 2004 at 17:50 UTC | |
by bowsie (Initiate) on Jan 11, 2005 at 20:20 UTC |