use strict; use warnings; # 18-01-2010 # cartesian product for 3 or more sets using Quantum::Superpositions # works because BINARY in Q::S allows to make quantized functions like U and p. sub p { return \@_; } sub U { my $i = $_[1]; my @element; # an element of the cartesian product if(ref($i) eq 'ARRAY') { while(1){ push @element,$i->[0]; $i=$i->[1]; last unless ref($i) eq 'ARRAY'; } }; @element=($_[0],@element,$i); print join(' ',@element)."\n" if ref($_[1]) eq 'ARRAY'; } use Quantum::Superpositions BINARY => ['main::U','main::p']; #U(any(1..2),p(any(9..13),p(any(0..1),p(any(2..4),any(5..8))))); U(any(1..2),p(any(2..4),any(5..10)));