Permutations: Difference between revisions
Content deleted Content added
→{{header|Scheme}}: impl #3 |
→{{header|Common Lisp}}: CL is about not repeating yourself |
||
Line 770:
Lexicographic next permutation:
<lang lisp>
(defun next-perm (vec cmp) ; modify vector
(declare (type (simple-array * (*)) vec))
(macrolet ((el (i) `(aref vec ,i))
(setf k (1+ len))
(return-from next-perm ll)))))))▼
(loop while (< (incf i) (decf k)) do
(rotatef (el i) (el k)))
;;; test code
</lang>
▲ (write-line a)
▲ (setf a (next-perm a #'char<))))</lang>
=={{header|D}}==
|