Skip to content

Instantly share code, notes, and snippets.

@DCPRevere
Created August 16, 2016 20:02
Show Gist options
  • Save DCPRevere/b224c2cf0d0a341edf2a966f2eb298f1 to your computer and use it in GitHub Desktop.
Save DCPRevere/b224c2cf0d0a341edf2a966f2eb298f1 to your computer and use it in GitHub Desktop.
(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