Hi, realy i need your help with this algorithm. what I need is another algorithm in order to improve my own.
example: my $firsSet = [ 'a', 'b', 'c', 'd', 'e' ]; my $secondSet = [ 'x', 'y', 'z' ]; my $thirdSet = [ 'a', 'x', 'b', 'y' ]; my $fourthSet = [ 'b', 'd', 'z' ]; my $counter = 0; foreach my $elm1 (@{$firstSet}) { foreach my $elm2 (@{$secondSet}) { foreach my $elm3 (@{$thirdSet}) { foreach my $elm4 (@{$fourthSet}) { print "$counter : $elm1, elm2 , elm3 , elm4\n"; $counter ++; } } } } # It prints each possible combination taken one element for each set. another (better way): my @Set = (); my $elements = {a=>1, b=>1, c=>1, d=>1, e=>1, x=>1, y=>1, z=>1}; $Set[0] = [ 'a', 'b', 'c', 'd', 'e' ]; $Set[1] = [ 'x', 'y', 'z' ]; $Set[2] = [ 'a', 'x', 'b', 'y' ]; $Set[3] = [ 'b', 'd', 'z' ]; my $counter = 0; @result = @{$Set[0]}; for (1 .. (scalar @Set) - 1) { my $temp = []; foreach my $result (@result) { foreach my $elm (@{$Set[$_]}) { if ($elements=>{$elm}) { #if I dont want repetitions push @{$temp}, $result.', '.$elm; $elements=>{$elm}=0; $counter++; }; }; }; @result = @{$temp}; }; print "@result\n"; But, both are still too slow. So, can you give me an idea to improve it?. someone tell me about mask, and bit operations. but i really dont know how to do it. so.. any suggestion?. there was a thread in a forum (here<http://forums.devshed.com/software-design-43/algorithm-design-536480.html>), but the solution was for python (recursive using "yield"). Thanks for your answer. Regards, Pablo Zea Aranibar Student from University UNSAAC Cusco - Peru