Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Answer: How can I find the union/difference/intersection of two arrays?

by DrHyde (Prior)
on Jun 16, 2003 at 14:20 UTC ( #266193=categorized answer: print w/replies, xml ) Need Help??

Q&A > arrays > How can I find the union/difference/intersection of two arrays? - Answer contributed by DrHyde

TheDamian's Quantum::Superpositions module can do this. Although it is slow, the code is quite readable:
use Quantum::Superpositions; my @a = (1,2,3,4,5,6,7,8,9,10); # integers my @b = (2,4,6,8,10,12,14,16,18,20); # doubled my @unionAB = sort { $a <=> $b } eigenstates( any(@a, @b) ); my @intersectionAB = sort { $a <=> $b } eigenstates( any(@a) == any(@b +) ); my @differenceAB = sort { $a <=> $b } eigenstates( any(@a) != all(@b +) );

  • Comment on Answer: How can I find the union/difference/intersection of two arrays?
  • Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2020-11-26 20:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?