Created
August 16, 2016 20:02
-
-
Save DCPRevere/b224c2cf0d0a341edf2a966f2eb298f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns chess-problem) | |
;; (:require [clojure.contrib.seq-utils :as s-utils])) | |
;; Backrow of the chess board. | |
;; Bishops are on different colours. | |
;; King has to be between the rooks. | |
;; A function that takes a number n | |
;; And returns n valid backrows. | |
(def std-backrow [:r :kn :b :ki :q :b :kn :r]) | |
(def inv-backrow [:r :kn :b :ki :b :q :kn :r]) | |
(defn gen-backrow [] | |
(shuffle std-backrow)) | |
(gen-backrow) | |
(defn gen-backrows [] | |
(repeatedly gen-backrow)) | |
(defn many-backrows [number] | |
(take number (gen-backrows))) | |
(defn bishop-index [row] | |
(keep-indexed | |
(fn [idx val] (when (= :b val) idx)) | |
row)) | |
(defn valid-bishops [row] | |
(odd? (apply - (bishop-index row)))) | |
(valid-bishops std-backrow) | |
(valid-bishops inv-backrow) | |
(defn valid-king [row] | |
) | |
;; (many-backrows 5) | |
;; (index :a [:a :b]) | |
;; (defn indexes [index item pred] | |
;; (if (my-pred item) | |
;; index | |
;; nil)) | |
;; (defn my-pred [item] | |
;; (= :b item)) | |
;; (keep-indexed #(indexes % %2 my-pred) | |
;; std-backrow) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment