http://www.perlmonks.org?node_id=266193


in reply to How can I find the union/difference/intersection of two arrays?

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 Re: How can I find the union/difference/intersection of two arrays?
  • Download Code