Created
August 22, 2016 00:43
-
-
Save eggsyntax/516d2beaca4f7cc55867c7d8267b7a09 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
(ns cuber.core) | |
;; octal numbers: | |
(def start [0 1 2 3 4 5 6 7]) | |
(def end [4 2 4 2 4 2 4 2]) | |
(defn modding [f] | |
;; identity | |
(fn [x] (mod (f x) 8))) | |
(def p (fn [v] (map (modding inc) v))) | |
(def m (fn [v] (map (modding dec) v))) | |
(def d (fn [v] (map (modding #(* % 2)) v))) | |
(def s (fn [v] (map (modding #(* %1 %1)) v))) | |
(def e (fn [v] (filter #(= (mod % 2) 0) v))) | |
(def ops [`p `m `d `s `e]) | |
(defn apply-ops [op-list v] | |
(let [op-fn-list (map resolve op-list)] | |
((apply comp (reverse op-fn-list)) v))) | |
(loop [] | |
(let [shuffled (shuffle ops) | |
num (+ 1 (rand-int (count shuffled))) | |
some-ops (take num shuffled) | |
result (apply-ops some-ops start)] | |
(println "trying" (map str some-ops)) | |
(println " " result) | |
(println) | |
(if (= result end) | |
(println "SUCCESS!") | |
(recur)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment