File: permut.mc

package info (click to toggle)
maxima 5.6-17
  • links: PTS
  • area: main
  • in suites: woody
  • size: 30,572 kB
  • ctags: 47,715
  • sloc: ansic: 154,079; lisp: 147,553; asm: 45,843; tcl: 16,744; sh: 11,057; makefile: 7,198; perl: 1,842; sed: 334; fortran: 24; awk: 5
file content (32 lines) | stat: -rw-r--r-- 979 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
;;; -*- Mode: Lisp -*-
;;;
;;; PERMUT: A Package for generating permutations

(includef (cond ((status feature ITS)     '|libmax;prelud >|)
		((status feature Multics) '|prelude|)
		((status feature Unix)    '|libmax//prelud.l|)
		(t (error '|Unknown system -- see MC:LIBMAX;INCLUD >|))))

(declare (mapex T))

(defun all_permutations (l)
   (if (null l) '(())
       (do ((elt (car l))
	    (permute (all_permutations (cdr l)) (cdr permute))
	    (ans))
	   ((null permute) ans)
	  (setq ans
		(append (permute_an_elt_through elt (car permute)) ans)))))

(defun permute_an_elt_through (elt l)
   (if (null l) (ncons (ncons elt))
       (cons (cons elt l)
	     (mapcar #'(lambda (x) (cons (car l) x))
		     (permute_an_elt_through elt (cdr l))))))

(defun $permutations (l)
   (if ($listp l)
       (cons '(MLIST) (mapcar #'(lambda (x) (cons '(MLIST) x))
			      (all_permutations (cdr l))))
       (displa l)
       (merror "~&Error, argument not a list---PERMUTATIONS~%")))