Blob


1 (defun make-position (row col)
2 (cons row col))
3 (defun position-row (pos)
4 (car pos))
5 (defun position-col (pos)
6 (cdr pos))
7 (defun positions-equal (a b)
8 (equal a b))
9 (defvar empty-board '())
10 (defun adjoin-position (row col positions)
11 (append positions (list (make-position row col))))
12 (defun attacks? (a b)
13 (let ((a-row (position-row a))
14 (a-col (position-col a))
15 (b-row (position-row b))
16 (b-col (position-col b)))
17 (cond
18 ((= a-row b-row) t)
19 ((= a-col b-col) t)
20 ((= (abs (- a-col b-col))
21 (abs (- a-row b-row))) t)
22 (t nil))))
23 (defun safe? (k positions)
24 (let ((kth-pos (nth (1- k) positions)))
25 (if (null (find-if
26 (lambda (pos)
27 (and (not (positions-equal kth-pos pos))
28 (attacks? kth-pos pos)))
29 positions))
30 t
31 nil)))