Created
September 26, 2012 07:45
-
-
Save t-ob/3786636 to your computer and use it in GitHub Desktop.
London Clojure Dojo September 2012 - Team 2
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 ldnclj-sep-2012.core) | |
| (defn split-seq [n s] | |
| (loop [ln n ls s r1 []] | |
| (cond | |
| (= ln 0) (vector r1 ls) | |
| :else (recur (dec ln) (rest ls) (conj r1 (first ls)))))) | |
| (defn balanced? [n] | |
| (let [s (str n) | |
| c (count s) | |
| [l r] ((juxt take drop) (/ c 2) s)] | |
| (if (> (count l) (count r)) | |
| (->> [(butlast l) r] | |
| (map (partial map #(Integer/parseInt (str %)))) | |
| (map (partial apply +)) | |
| (apply =)) | |
| (recur (Integer/parseInt (str (apply str l) "7" (apply str r))))))) | |
| (defn sensible-balanced? [n] | |
| (let [digits (map #(- (int %) (int \0)) (str n)) | |
| m (/ (count digits) 2)] | |
| (= (apply + (take (int m) digits)) | |
| (apply + (drop m digits))))) | |
| (defn pth [n] | |
| (fn [& args] (apply n (reverse args))) ) | |
| (defn rotate-seq [i lst] | |
| (cond (= 0 i) lst | |
| (> 0 i) (recur (mod i (count lst)) lst) | |
| :else (let [new-lst (conj (vec (rest lst)) (first lst))] | |
| (recur (dec i) new-lst))) | |
| ) | |
| (defn new-rotate [n c] | |
| (->> (split-at n c) | |
| (reverse) | |
| (apply concat))) | |
| (-> 5 | |
| (inc)) | |
| (->> (cycle [1 2 3 4 5]) | |
| (drop (mod -2 5)) | |
| (take 5)) | |
| (defn new-new-rotate [n c] | |
| (->> (cycle c) | |
| (drop (mod n (count c))) | |
| (take (count c)))) | |
| (-> inc | |
| (map [1 2 3 4 5])) | |
| (->> [1 2 3 4 5] | |
| (map inc)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment