joni has asked for the wisdom of the Perl Monks concerning the following question:
Hi there. I want to recursively concatenate (union) sets that are not disjointed (the intersected set is not empty). For example, if I have the sets
(0) (0 1) (0 1 2) (1 2 3) (6 4 5)
The output should be:
This is the code when I compare iteratively sets one by one:((0 1 2 3) (4 5 6)
The output is (not what I want):use Set::Scalar; for $i ( 0 .. 4) {$cluster[$i] = Set::Scalar->new;} $cluster[0]->insert(0); $cluster[1]->insert(0,1); $cluster[2]->insert(0,1,2); $cluster[3]->insert(1,2,3); $cluster[4]->insert(5,6,4); for $i ( 0 .. 4) { for $j ( $i+1 .. 4) { if ($cluster[$i]->is_properly_intersecting($cluster[$j])) {$cluste +r[$i]=$cluster[$i]+$cluster[$j];$cluster[$j]->clear;} }}
(0) (0 1 2 3) (0 1 2) () (4 5 6)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How can sets be recursively concatenated when intersecting with each other
by Corion (Patriarch) on Apr 24, 2011 at 11:04 UTC | |
Re: How can sets be recursively concatenated when intersecting with each other
by jaredor (Priest) on Apr 24, 2011 at 14:02 UTC | |
Re: How can sets be recursively concatenated when intersecting with each other
by jdporter (Paladin) on Apr 25, 2011 at 06:44 UTC | |
Re: How can sets be recursively concatenated when intersecting with each other
by SuicideJunkie (Vicar) on Apr 24, 2011 at 21:56 UTC | |
Re: How can sets be recursively concatenated when intersecting with each other
by wind (Priest) on Apr 25, 2011 at 07:30 UTC |
Back to
Seekers of Perl Wisdom