;;; Exercice 1 ;; 1. (0 1 2 3) ;; 2. (1 2 4 8) ;; 3. (defun mystere (size &key (initial-element 0) (suivant #'1+)) (if (zerop size) '() (cons initial-element (mystere (1- size) :initial-element (funcall suivant initial-element) :suivant suivant)))) ;; ou plus élégant (defun mystere (size &key (initial-element 0) (suivant #'1+)) (labels ((aux (size initial-element) (if (zerop size) '() (cons initial-element (aux (1- size) (funcall suivant initial-element)))))) (aux size initial-element))) ;;; Exercice 2 (defmacro c-while (test &body body) (let ((count (gensym))) `(let ((,count 0)) (do () ((not ,test) ,count) (incf ,count) ,@body)))) ;;; Exercice 3 (in-package :sudoku) (defun check-coord (grid coord) (let ((assigned (assigned (the-cell grid coord)))) (or (not assigned) (and (member assigned +digits+) (let ((coords-to-forbid (coords-to-forbid coord))) (not (member assigned (mapcar #'(lambda (coord) (assigned (the-cell grid coord))) coords-to-forbid)))))))) (defun check-grid (grid) (every #'(lambda (coord) (check-coord grid coord)) *coordinates*)) ;;; Exercice 4 ;; 1. (defclass regular (polygon) ((n :initarg :number-of-sides :accessor number-of-sides) (side :initarg :side :accessor side)) (:documentation "class of regular polygons")) ;; 2. (defun make-regular-polygon (n side) (make-instance 'regular :number-of-sides number-of-sides :side side)) ;; 3. Il faut implémenter la méthode: sides-lengths ((p regular)) ;; 4. (defmethod perimeter ((p regular)) (* (number-of-sides p) (side p))) ;; 5. (defclass colored-mixin () ((color :initform +black+ :initarg :color :accessor color))) ;; 6. (defclass polygon (colored-mixin) ())