Skip to content

Instantly share code, notes, and snippets.

@niksudan
Created January 22, 2016 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niksudan/4598fd85409fd3d618f3 to your computer and use it in GitHub Desktop.
Save niksudan/4598fd85409fd3d618f3 to your computer and use it in GitHub Desktop.
n queens problem [Clojure]
(defn n-queens [n]
(def nList
(case (mod n 6)
2 (concat
(for [i (range 1 (+ (/ n 2) 1))] (* i 2))
(concat
(list 3 1)
(when (> n 6) (for [i (range 4 (+ (/ n 2) 1))] (- (* i 2) 1)))
(when (> n 4) (list 5))
)
)
3 (concat
(concat
(for [i (range 2 (+ (/ n 2) 1))] (* i 2))
(list 2)
)
(concat
(for [i (range 3 (+ (/ n 2) 1))] (- (* i 2) 1))
(list 1 3)
)
)
(if (even? n)
(concat
(for [i (range 1 (+ (/ n 2) 1))] (* i 2))
(for [i (range 1 (+ (/ n 2) 1))] (- (* i 2) 1))
)
(concat
(for [i (range 1 (/ n 2))] (* i 2))
(for [i (range 1 (+ (/ n 2) 1))] (- (* i 2) 1))
)
)
)
)
(for [i (range n)]
(str (char (+ 97 i)) (nth nList i))
)
)
@niksudan
Copy link
Author

This is an awful implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment