Clojure的没那么夸张
递归写法也就8行 (不算空行和最后一行打印)
(defn qtest [qcol qvect]
(letfn [(check? [[row col]] (or (= qcol col) (= qcol (- col (+ row 1))) (= qcol (+ col (+ row 1)))))]
(empty? (filter check? (map-indexed vector (rseq qvect))))))
(defn qsolve [board-size qvect]
(doseq [p (range board-size)]
(if (qtest p qvect)
(let [qnew (conj qvect p)]
(if (= (count qnew) board-size) (println qnew) (qsolve board-size qnew))))))
(qsolve 8 [])
八皇后问题haskell版正在做彩票数据的多维度分析工具,意识到选择一门表现力高的语言非常重要。先问一个问题,如果要找bug的话,你愿意只在5行里找,还是在50行里找呢?这不仅是一个关乎生产力的问题,...