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

Re: gen-permutation



> Subject    gen-permutation
>
>Are you sure you're not a college student looking for the answer to a
>homework question?  This sounds like a question they would have put on a
>final exam for the undergraduate programming course at MIT.  Never mind,
>here's a version of what you want.
>
>(defun gen-permutation (list-to-permute)
>  (if (null (cdr list-to-permute))
>    (list list-to-permute)
>    (mapcan
>     #'(lambda (x)
>         (map 'list #'(lambda (y) (cons x y))
>              (gen-permutation (remove x list-to-permute))))
>     list-to-permute)))
>
>Laura
>(former teaching assistant)


Dear Laura,

My knowledge of programming is very much limited to the composition.
I am working in Lisp environment ("Symbolic Composer" by Peter Stone) and
in many instances have to write my own functions.

(gen-permutation '(a a b b))

You gen-permutation output is:

-> ((a b) (a b) (a b) (a b) (b a) (b a) (b a) (b a))

I'm looking for:

-> ((a a b b) (a b a b) (a b b a) (b a a b) (b a b a) (b b a a))

permute-uniqe?

Janusz