Maîtrise d'Informatique - 1998-1999, corrections
|
(defun num_bin(n m)
(if (= m 0) ()
(if (pair n) (append (num_bin (/ n 2) (- m 1)) (list 0))
(append (num_bin (/ (- n 1) 2) (- m 1)) (list 1))
)
)
)
(defun pair(n)
(if (= (rem n 2) 1) () T)
)
;**********************************************
(defun bin_num(l)
(if l (if (= (dernier l) 1) (+ 1 (* 2 (bin_num (miroir (cdr (miroir l))))))
(* 2 (bin_num (miroir (cdr (miroir l)))))
)
0)
)
(defun dernier (l)
(if (cdr l)
(dernier (cdr l))
(car l)))
(defun miroir (l)
(if l (append (miroir (cdr l))(list (car l)))
()
))
;******************************
(defun numlist_binlist (l m)
(if l (cons (num_bin (car l) m) (numlist_binlist (cdr l) m))
()
)
)
;**********************************
(defun nth (n l)
(if (= n 1) (car l)
(nth (1- n) (cdr l))
))
;*************************************
(defun isone (l n)
(if (= (nth n l) 1) t ())
)
;***********************************
(defun firstone(l)
(if l (if (= (car l) 1) 1 (+ 1 (firstone (cdr l))))
1)
)
;**********************************
(defun zeros(n)
(if (= n 0) () (cons 0 (zeros (- n 1))))
)
;************************************
(defun allzero(l)
(if l (if (= (car l) 0) (allzero (cdr l)) ())
t
)
)
;********************************
(defun summod2(l1 l2)
(if l1 (cons (if (= (car l1) (car l2)) 0 1) (summod2 (cdr l1) (cdr l2)))
()
)
)
;******************************
(defun posone(l n)
(if l (if (isone (car l) n) 1 (+ 1 (posone (cdr l) n)))
1)
)
;************************
(defun summod2list (l)
(if (cdr l) (summod2list (cons (summod2 (car l) (cadr l)) (cddr l)))
(car l))
)
;******************************
(defun paritylist(l)
(if (allzero (summod2list l)) t ())
)
;****************************
(defun coup(l)
(if (paritylist (numlist_binlist l 10)) () (decide l 1 1)
)
)
(defun substi (s1 s2 s)
(if (atom s) (if (equal s s2) s1 s
)
(cons (substi s1 s2 (car s)) (substi s1 s2 (cdr s))
)
)
)
(defun decide(l n a)
(if (> (nth n l) a)
( if (paritylist (numlist_binlist (substi (- (nth n l) a) (nth n l) l)
10))
(list n a)
(decide l n (+ 1 a))
)
(decide l (+ 1 n) 1)
)
)
Vincent Vajnovszki
jeu 4 mai 13:03:55 NFT 2000