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

Re: [MacPerl] 2D Permutations



bart.lateur@skynet.be (Bart Lateur) wrote:

>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?
>
>	sub distribute {
>	    my $first = shift;
>	    @_ or return @$first;
>	    return map { my $item = $_; map "$item$_", distribute(@_) }
>	      @$first;
>	}

I assumed that David was using an iterative approach so that the
enumerations never had to occupy memory all at once.  If memory is no
concern, then clearly the recursive approach is much more
straightforward.

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

You're right.  Permutations are different orderings of a collection of
objects.  This is really just enumeration.


  -------------------                            -------------------
  Ken Williams                             Last Bastion of Euclidity
  ken@forum.swarthmore.edu                            The Math Forum

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