Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2010
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.15 KB | None | 0 0
  1. (ns queens)
  2.  
  3. ;; Aim of the program is to put N queens on a N x N board
  4. ;; (for example 8 queens on a 8 x 8 board ) avoiding each
  5. ;; queen to eat one of the others.
  6.  
  7. (defstruct queens :board :current-queen)
  8.  
  9.  
  10. (defn next-solution-queens
  11.   "Compute the next valid position of the queens
  12.  return nil if no more solutions are avaiable."
  13.   [queens]
  14.   nil)
  15.  
  16. (defn next-solution-actual-queen
  17.   "Compute the next valid position for the actual queen
  18.  return nil if there is no valid solution."
  19.   [queens]
  20.   nil)
  21.  
  22. (declare diagonal-down-busy?, diagonal-up-busy?)
  23.  
  24. (defn line-busy?
  25.   "Check if the line on wich the current queen is located is free"
  26.   [queens]
  27.   (let [{board :board current-queen :current-queen} queens
  28.         line (nth board current-queen)]
  29.     (> (count (filter #{line} board)) 1)))
  30.  
  31. (defn is-position-valid?
  32.   "Return true if the position of the actual queen is valid
  33.  returns false otherwise."
  34.   [queens]
  35.   (let [{board :board current-queen :current-queen} queens]
  36.     (or (= current-queen 0)
  37.         (not (or (line-busy? queens)
  38.                  (diagonal-up-busy? queens)
  39.                  (diagonal-down-busy? queens))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement