Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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 admiring the Monastery: (5)
As of 2025-11-11 13:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (68 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.