Created
November 9, 2015 03:23
-
-
Save escherize/62553ded59ec7e289be6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
;; image at: http://take.ms/VaXll | |
(def g {:a {:white :a :black :b} | |
:b {:white :d :black :c} | |
:c {:white :g :black :d} | |
:d {:white :c :black :e} | |
:e {:white :f :black :f} | |
:f {:white :b :black :g} | |
:g {:white :e :black :a}}) | |
(defn follow-black [k] | |
(get-in g [k :black])) | |
(defn follow-white [k] | |
(get-in g [k :white])) | |
(defn build-instructions [n] | |
(let [counts (->> n | |
str | |
(re-seq #"\d") | |
(mapv read-string)) | |
next-fn (cycle [follow-black follow-white])] | |
(drop-last | |
(mapcat (fn [c nf] (repeat c nf)) | |
(interleave counts (repeat 1)) | |
next-fn)))) | |
(defn compute [instructions] | |
((apply comp (reverse instructions)) :a)) | |
(defn divisible-by-7? [n] | |
(= :a (-> n build-instructions compute))) | |
;;(map #(do [% (divisible-by-7? %)]) (range 30)) | |
;;=> [[0 true] | |
[1 false] | |
[2 false] | |
[3 false] | |
[4 false] | |
[5 false] | |
[6 false] | |
[7 true] | |
[8 false] | |
[9 false] | |
[10 false] | |
[11 false] | |
[12 false] | |
[13 false] | |
[14 true] | |
[15 false] | |
[16 false] | |
[17 false] | |
[18 false] | |
[19 false] | |
[20 false] | |
[21 true] | |
[22 false] | |
[23 false] | |
[24 false] | |
[25 false] | |
[26 false] | |
[27 false] | |
[28 true] | |
[29 false]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment