看板 Programming 關於我們 聯絡資訊
ANSI Common-Lisp 版本: (setf x '(3 4 5 6 7)) (defun repeat-cdr (x i) (cond ((= i 0) x) (t (repeat-cdr (cdr x) (- i 1))) ) ) (defun item (x i) (cond ((= i 1) (cons (car x) nil)) (t (append (item x (- i 1)) (cons (car (repeat-cdr x (- i 1))) nil))) ) ) (defun ascend (n) (cond ((= n 1) (cons n nil)) (t (append (ascend (- n 1)) (cons n nil))) ) ) (defun palindrome (n) (cond ((= n 1) (cons n nil)) (t (append (ascend (- n 1)) (cons n nil) (reverse (ascend (- n 1))))) ) ) (defun odd-size (x) (cond ((null (car x)) nil) ((= 0 (mod (length (car x)) 2)) (odd-size (cdr x))) (t (cons (car x) (odd-size (cdr x)))) ) ) (defun diamond (x) (odd-size (mapcar #'(lambda (y) (item x y)) (palindrome (length x)))) ) (defun print* (x) (cond ((atom x) (princ x)) ((listp x) (mapcar #'(lambda (y) (print* y)) x) (terpri)) ) ) (defun repeat-print (x i) (cond ((< i 1) nil) ((= i 1) (princ x)) (t (repeat-print x (- i 1)) (princ x)) ) ) (mapcar #'(lambda (y) (repeat-print #\space (/ (- (length x) (length y)) 2)) (print* y)) (diamond x)) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.112.224.95
buganini:忽然有點想po一篇偽whitespace版XD 220.135.231.23 03/24 02:30
buganini:算了怕被噓:p 220.135.231.23 03/24 02:30
yoco315:whitespace 好阿 XDDD 118.160.109.50 03/24 09:03