Blame


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