Skip to content

Instantly share code, notes, and snippets.

@kaikai2
Last active December 13, 2015 21:28
Show Gist options
  • Save kaikai2/4977690 to your computer and use it in GitHub Desktop.
Save kaikai2/4977690 to your computer and use it in GitHub Desktop.
;定义一个接受一系列数字的函数,并在若且唯若每一对(pair)数字的差为一时,返回真,使用 ;(a) 递归 ;(b) do
;http://acl.readthedocs.org/en/latest/zhCN/ch5-cn.html#chapter-5-exercises
;定义一个接受一系列数字的函数,并在若且唯若每一对(pair)数字的差为一时,返回真,使用
;(a) 递归
;(b) do
(defun linked-r (lst)
(or (null lst)
(null (cdr lst))
(and (diff-1 (car lst) (cadr lst))
(linked-r (cdr lst)))))
(defun linked-do (lst)
(let ((r t))
(do ((rest (cdr lst) (cdr rest))
(i (car lst) (car rest))
(j nil i))
((null i) 'done)
(unless (or (null i)
(null j)
(diff-1 i j))
(setf r nil))
)
r))
(defun diff-1 (a b)
(or (eql a (+ b 1))
(eql b (+ a 1))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment