Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Set intersection problem

by salva (Canon)
on May 23, 2023 at 14:02 UTC ( [id://11152389]=note: print w/replies, xml ) Need Help??


in reply to Set intersection problem

I am not sure I completely understand your problem, so maybe the following idea doesn't make sense, but, have you consider inverting the approach?

For every element make an array with the names of the sets containing it. Once that is done, you can reverse it again, converting the list of sets into a key and use it to group the elements:

# untested my %sets = { A => [1,2,3], B => [3, 4], C => [1, 3, 4] } my %in; for my $set (keys %sets) { for my $element (@{$sets{$set}}) { push @{$in[$element] //= []}, $set; } } my %parts; for my $element (keys %in) { my $key = join("/", sort @{$in{$element}}); push @{$parts{$key} //= []}, $element } Dump \%parts;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-09-20 09:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (25 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.