(defmacro for-all (x op xs)
`(remove-if-not #'(lambda (y) (,op y x)) xs))
(defun qsort (nums)
(if (not nums)
()
(let ((x (first nums))
(xs (rest nums)))
(if (eq x nil)
()
(append
(qsort (for-all x < xs))
(list x)
(qsort (for-all x >= xs)))))))
Permutation
(defun remove-first (n nums)
(remove n nums :count 1))
(defun join-sublists (superlist)
(reduce #'(lambda (l1 l2) (append l1 l2)) superlist))
(defun permute-sorted-list (nums perm)
(if (eq nums nil)
(list perm)
(let ((unique-nums (remove-duplicates nums))) (join-sublists
(mapcar (lambda (n)
(permute-sorted-list (remove-first n nums) (append perm (list n))))
unique-nums)))))
(defun permutation (nums)
(permute-sorted-list (sort nums #'<) '()))
5 則留言:
You are terrific. I like this remarkable things, Keep it up and keep on writing
I like to see some other posts on the same subject! Very useful informative info!!
I must thank you for the efforts you’ve put in writing this blog. Awesome!
You’ve written nice post, I am gonna bookmark this page, thanks for info.
Hi very nice blog! I'll bookmark this website. Thanks for blogging.
張貼留言