[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] 2D Permutations



On Wed, 29 Nov 2000 01:11:09 -0600, Ken Williams wrote:

>I couldn't really Benchmark your module, because running it more than
>once seems to trigger an infinite loop.

Always a bad sign.

Anyway, what about this approach?

	my @ary = ( [ "A", "B" ],
	    [ "C", "D", "E" ],
	    [ "F", "G", "H" ]
	  );

	sub distribute {
	    my $first = shift;
	    @_ or return @$first;
	    return map { my $item = $_; map "$item$_", distribute(@_) }
	      @$first;
	}

	$, = "\n"; $\ = "\n";
	print distribute(@ary);
-->
	ACF
	ACG
	ACH
	ADF
	ADG
	ADH
	AEF
	AEG
	AEH
	BCF
	BCG
	BCH
	BDF
	BDG
	BDH
	BEF
	BEG
	BEH

p.s. This doesn't really sound like a "permutation" to me.

-- 
	Bart.

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org