Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Set intersection problem

by tybalt89 (Monsignor)
on May 23, 2023 at 15:30 UTC ( [id://11152394]=note: print w/replies, xml ) Need Help??


in reply to Set intersection problem

If you don't care about which sets an item belongs to, and there are no duplicates within any set:

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11152381 use warnings; my %sets = ( A => [1,2,3], B => [3, 4], C => [1, 3, 4] ); my %seen; my @items = sort grep $seen{$_}++ == 1, map @$_, values %sets; print "Items in more than one set: @items\n";

Outputs:

Items in more than one set: 1 3 4

Log In?
Username:
Password:

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

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





    Results (23 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.