help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: All Possible Combinations


From: Lennart Borgman
Subject: Re: All Possible Combinations
Date: Wed, 3 Jun 2009 11:55:55 +0200

On Wed, Jun 3, 2009 at 11:09 AM, Nordlöw <per.nordlow@gmail.com> wrote:
> Hey!
>
> I want a function that generates all possible combinations (ordering)
> of the elements in a list (or sequence if possible). Here is my
> mockup:
>
> (defun all-combinations (n)
>  "Generate a listing of all the possible combinations of the
> elements in the sequence N. Time-Complexity is N!"
>  (let (all)
>    all))
>
> For example (all-combinations '(a b c)) should return '((a b c) (a c
> b) (b a c) (b c a) (c a b) (c b a))
>
> Has somebody written such a function, preferrably in an iterative
> rather than recursive way.

Would not that require building a stack to keep track of state just as
recursion would do internally?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]