(define (queens board-size)
(define (safe? k position)
(define (iter last-element front-lst col-num k)
(define (ok? l-e car-lst)
(and (not (= l-e car-lst))
(not (= (abs (- l-e car-lst)) (abs (- k col-num))))))
(if (null? front-lst)
true
(and (ok? last-element (car front-lst))
(iter last-element (cdr front-lst) (++ col-num) k))))
(let ((l-e (car (my-reverse position)))
(f-l (my-remove (car (my-reverse position)) position)))
(iter l-e f-l 1 k)))
(define empty-board (list nil))
(define (adjoin-position new-row k rest-of-queens)
(append rest-of-queens (list new-row)))
(define (queen-cols k)
(if (= k 0)
(list empty-board)
(filter
(lambda (positions) (safe? k positions))
(my-flatmap
(lambda (rest-of-queens)
(map (lambda (new-row)
(adjoin-position new-row k rest-of-queens))
(enumerate-interval 1 board-size)))
(queen-cols (-- k))))))
(queen-cols board-size))