在1到1+n的数字中,找出缺失和重复的数字
哪位朋友帮忙写一个小插件:在1到1+n的数字中,找出缺失和重复的数字。就比如说是1到1000 里面的连续数字找出缺失的和重复的。http://bbs.mjtd.com/thread-186219-1-1.html 试试
(defun samecount (lst / a b n)
(while lst
(setq n (length lst)
a (car lst)
lst (vl-remove a lst)
b (cons (cons a (- n (length lst))) b)
)
)
)
(defun delsame (lst / a b)
(while (setq a (car lst))
(if
(vl-position a b)
nil
(set 'b (cons a b))
)
(setq lst (cdr lst))
)
(setq b (reverse b))
b
)
(defun tt (lst from to / a n lst1)
(setqa (samecount lst)
lst (delsame lst)
n (- to from)
)
(repeat (1+ n)
(if(not(member from lst))
(setq lst1 (cons from lst1))
)
(setq from (1+ from))
)
(list(vl-remove-if '(lambda (x) (= 1 (cdr x))) a)
(reverse lst1)
)
)
(tt '(1 2 3 5 7 9 1 2) 1 11)=>(((2 . 2) (1 . 2)) (4 6 8 10 11))
页:
[1]