You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
typesetting/csp/hacs-test-workbench.rkt

28 lines
1004 B
Racket

6 years ago
#lang debug racket
6 years ago
(require sugar/debug "hacs.rkt")
6 years ago
(current-inference forward-check)
6 years ago
(current-select-variable mrv)
6 years ago
(current-order-values shuffle)
6 years ago
(current-shuffle #true)
;; queens problem
;; place queens on chessboard so they do not intersect
(define queens (make-csp))
6 years ago
(define qs (for/list ([q 8]) (string->symbol (format "q~a" q))))
6 years ago
(define rows (range (length qs)))
(add-vars! queens qs rows)
(define (q-col q) (string->number (string-trim (symbol->string q) "q")))
(for* ([qs (in-combinations qs 2)])
(match-define (list qa qb) qs)
(match-define (list qa-col qb-col) (map q-col qs))
(add-constraint! queens
(λ (qa-row qb-row)
(nor
(= (abs (- qa-row qb-row)) (abs (- qa-col qb-col))) ; same diagonal?
(= qa-row qb-row))) ; same row?
(list qa qb)))
#;(time-named (solve queens))
(parameterize ([current-solver min-conflicts])
(time-named (solve queens)))