in reply to Re: cross combinations
in thread cross combinations

Cool solution -- but the original isn't recursive, so I'm not sure this is quite apples to oranges for comparing length.

For the OP, I'm curious to know what about Perl6 makes this easier than Perl5. Or is that the point? Is the point just to play with perl6's new syntax?

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re^3: cross combinations
by Perl Mouse (Chaplain) on Oct 28, 2005 at 11:56 UTC
    Oh, there's a three line non-recursive solution as well, using the same algorithm (as the recursive solution). I just find recursion much easier.
    sub cross { my @r = []; @r = map {my $l = $_; map {[@$_, $l]} @r} @$_ for @_; @r; }
    What I don't understand about the Perl6 solution is the need to count how many elements will be returned.
    Perl --((8:>*