[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: permutation

William James

12/30/2015 4:16:00 AM

Joshua Taylor wrote:

> (defun permute (list)
> (cond
> ((endp list) list) ; no permutations of ()
> ((endp (cdr list)) (list list)) ; one permutation of (x)
> (t (loop :for subpermutation :in (permute (cdr list)) :nconc
> (loop :for i :from 0 :to (length subpermutation)
> :collecting (append (subseq subpermutation 0 i)
> (cons (car list) (subseq subpermutation i))))))
> ))

MatzLisp (Ruby):

[2,3,4].permutation.to_a
==>[[2, 3, 4], [2, 4, 3], [3, 2, 4], [3, 4, 2], [4, 2, 3], [4, 3, 2]]


--
Amazon bans book. After nearly a month on the site, all traces of the book and
its 80 reviews have been removed.
http://jamesfetzer.blogspot.com/2015/11/debunking-sandy-hook-debunk...
https://www.youtube.com/watch?v=E...