1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
(defun make-amida (list)
  (unless (equal list '(0))
    (let ((n (1- (length list))))
      (nconc (make-amida (remove n list))
             (loop for x from (1- n) downto (position n list) collect x)))))

(defun print-amida (x result)
  (let ((n (1- (length result))))
    (format t "~{~D~^ ~}~&" (loop for x from 0 to n collect x))
    (dolist (i x)
      (let ((str (format nil "~V@{| ~}|" n t)))
        (setf (aref str (+ i i 1)) #\-)
        (write-line str)))
    (format t "~{~D~^ ~}~&" result)))

(let ((list '(3 5 2 4 0 1)))
  (print-amida (make-amida list) list))