Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns queens)
- ;; Aim of the program is to put N queens on a N x N board
- ;; (for example 8 queens on a 8 x 8 board ) avoiding each
- ;; queen to eat one of the others.
- (defstruct queens :board :current-queen)
- (defn next-solution-queens
- "Compute the next valid position of the queens
- return nil if no more solutions are avaiable."
- [queens]
- nil)
- (defn next-solution-actual-queen
- "Compute the next valid position for the actual queen
- return nil if there is no valid solution."
- [queens]
- nil)
- (declare diagonal-down-busy?, diagonal-up-busy?)
- (defn line-busy?
- "Check if the line on wich the current queen is located is free"
- [queens]
- (let [{board :board current-queen :current-queen} queens
- line (nth board current-queen)]
- (> (count (filter #{line} board)) 1)))
- (defn is-position-valid?
- "Return true if the position of the actual queen is valid
- returns false otherwise."
- [queens]
- (let [{board :board current-queen :current-queen} queens]
- (or (= current-queen 0)
- (not (or (line-busy? queens)
- (diagonal-up-busy? queens)
- (diagonal-down-busy? queens))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement