((fn [s v] (some #(= s %) (map #(subvec v % (count s)) (range 0 (inc (- (count v) (count s))))))) [2 3] [1 2 3])
nil
(let [l [1 2 3 3 2 1] p (partition 2 1 l)] (split-at (inc (count (first (split-with #(not (= (first %) (first (rest %)))) p)))) l))
[(1 2 3) (3 2 1)]
(defn remove-from-vector "Takes a vector and an index, returns a vector with the member at that index removed." [vc indx] (vec (concat (subvec vc (inc indx)) (subvec vc 0 indx))))
#'user/remove-from-vector
(let [sqrt2 #(loop [x %2 i 0] (if (> i %3) x (recur (/ (+ x (/ %1 x)) 2) (inc i))))] (float (sqrt2 (/ 41 20) 2 8)))
1.4317821
(let [midpoint (fn [coll] (let [idx (quot (count coll) 2)] [(vec (take idx coll)) (nth coll idx) (vec (drop (inc idx) coll))]))] (midpoint [1 2 3 4 5 6 7]))
[[1 2 3] 4 [5 6 7]]
(let [sqrt2 #(loop [x %2 i 0] (if (> i %3) x (recur (/ (+ x (/ %1 x)) 2) (inc i))))] (float (sqrt2 (/ 41 20) 2 7)))
1.4317821
(= ((fn [x y] (keep-indexed #(if (not= 0 (rem (inc %) y)) %2) x)) [1 2 3 4 5 6 7 8] 3) [1 2 4 5 7 8])
true
(vec (concat (subvec [0 1 2 3 4 5 6 7 8 9 10] 0 3) (subvec [0 1 2 3 4 5 6 7 8 9 10] (inc 3))))
[0 1 2 4 5 6 7 8 9 10]
(let [f (fn [s] (->> (iterate #(.indexOf s "<C>" (inc %)) -1) (drop 1) (take-while (complement neg?))))] (f "la la la <C> la la <C> <C> foo <C>"))
(9 19 23 31)
(let [l [1 2 3 4 4 3 2 1] p (partition 2 1 l)] (split-at (inc (count (first (split-with #(not (= (first %) (first (rest %)))) p)))) l))
[(1 2 3 4) (4 3 2 1)]
((fn [s v] (some #(= s %) (map #(subvec v % (+ % (count s))) (range 0 (inc (- (count v) (count s))))))) [1 2 3] [1 1 2 3])
true
((fn [s v] (some #(= s %) (map #(subvec v % (+ % (count s))) (range 0 (inc (- (count v) (count s))))))) [2 3 4] [1 2 3 4])
true
(defn tree-depth-check-empty [branch? children empty root] (let [walk (fn walk [node] (if (branch? node) (let [children (children node)] (if (empty? children) empty (inc (reduce max (map walk children))))) 0))] (walk root)))
#'user/tree-depth-check-empty
(= ((fn [x y] (keep-indexed #(if (not= 0 (rem (inc %) y)) %2) x)) [1 2 3 4 5 6 7 8] 3) '(1 2 4 5 7 8))
true
(letfn [(map-vals [m f & args] (into {} (for [[k v] m] [k (apply f v args)])))] (map-vals {:a {:x 5, :y 6}, :b {:x 7, :y 8}} map-vals inc))
{:a {:x 6, :y 7}, :b {:x 8, :y 9}}
(let [v [{:name "Chris", :age 10, :id 0} {:name "Chris", :age 28, :id 1} {:name "Adam", :age 25, :id 2}] m (zipmap (map :id v) v)] (update-in m [0 :age] inc))
{0 {:age 11, :id 0, :name "Chris"}, 1 {:age 28, :id 1, :name "Chris"}, 2 {:age 25, :id 2, :name "Adam"}}
(loop [x 0 y 0 iterations 0] (let [new-x (+ x (dec (rand-int 3))) new-y (+ y (dec (rand-int 3)))] (if (= new-x new-y 5) iterations (recur new-x new-y (inc iterations)))))
2188
(#(apply conj (reduce (fn [[runs part] i] (if (= i (inc (peek part))) [runs (conj part i)] [(conj runs part) [i]])) [[] [(first %)]] (rest %))) [1 2 3 5 6 8])
[[1 2 3] [5 6] [8]]
(let [v [[0 12] [1 23] [3 65]] m (apply max (map first v)) o (vec (repeat (inc m) 0))] (reduce (fn [o [k v]] (assoc o k v)) o v))
[12 23 0 65]
(reduce (fn [ranges [start end :as el]] (let [[s e] (peek ranges)] (if (> start (inc e)) (conj ranges el) (conj (pop ranges) [s end])))) [[1 1]] [[1 2] [3 3] [4 5]])
[[1 5]]
(defn lazy-look-and-generate [] (iterate (fn [x] (mapcat (fn [n] (loop [x1 (first n) y (rest n) count 1] (if (= x1 (first y)) (recur x1 (rest y) (inc count)) (conj nil count x1)))) x)) [1]))
#'user/lazy-look-and-generate
((fn [v] (->> v (map-indexed vector) (mapcat (fn [[i x]] (map #(-> [i %]) (range 2 (inc x))))) (reductions (fn [v [i x]] (assoc v i x)) (vec (repeat (count v) 1))))) [2 1 4])
([1 1 1] [2 1 1] [2 1 2] [2 1 3] [2 1 4])
(defn spans ([coll] (spans (rest coll) 1 (first coll))) ([coll acc item] (cond (empty? coll) (cons acc nil) (= item (first coll)) (recur (rest coll) (inc acc) item) :else (lazy-seq (cons acc (spans (rest coll) 1 (first coll)))))))
#'user/spans
(let [coll [:N :NE :E :SE :S :SW :W :NW] reversed (zipmap coll (range)) shift #(nth coll (mod (% (reversed %2)) (count coll))) left (partial shift dec) right (partial shift inc)] (-> :N left left left right))
:W
(defn choose-k [coll k] (let [n (count coll)] (if (<= k 1) (map vector coll) (reduce into (sorted-set) (for [i (range 1 (inc n))] (map #(into [(nth coll (dec i))] %) (choose-k (drop i coll) (dec k))))))))
#'user/choose-k
(defn spans ([coll] (spans (rest coll) 1 (first coll))) ([coll acc item] (cond (empty? coll) (cons acc nil) (= item (first coll)) (recur (rest coll) (inc acc) item) :else (lazy-seq (cons acc (spans (rest coll) 0 (first coll)))))))
#'user/spans
(let [better-age-atom (atom {:agec 0, :ages 0})] (defn age-avg [] (let [{:keys [agec ages]} @better-age-atom] (/ ages agec))) (defn age+ [age] (if (and (< 0 age) (> 120 age)) (swap! better-age-atom #(-> %1 (update-in [:agec] inc) (update-in [:ages] + age))))))
#'user/age+
(let [limit 5 original [:a :b :c :d :e]] (map #(map (partial nth original) %) (nth (iterate #(for [p % n (range (inc (count p)))] (concat (take n p) [(count p)] (drop n p))) [[0]]) (dec limit))))
((:e :d :c :b :a) (:d :e :c :b :a) (:d :c :e :b :a) (:d :c :b :e :a) (:d :c :b :a :e) (:e :c :d :b :a) (:c :e :d :b :a) (:c :d :e :b :a) (:c :d :b :e :a) (:c :d :b :a :e) (:e :c :b :d :a) (:c :e :b :d :a) (:c :b :e :d :a) (:c :b :d :e :a) (:c :b :d :a :e) (:e :c :b :a :d) (:c :e :b :a :d) (:c :b :e :a :d) (:c :b :a :e :d) (:c :b :a :d :e) (:e :d :b :c :a) (:d :e :b :c :a) (:d :b :e :c :a) (:d :b :...
(let [❄ inc ☃ 1] (-> ☃ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄ ❄))
42
(let [g [1 5 3 3 2 4 5 5 4 5 1 2 1 2 3 5] [v x c] (reduce (fn [[v x c] y] (if (= x y) [v x (inc c)] [(conj v [x c]) y 1])) [[] (first g) 1] (rest g))] (conj v [x c]))
[[1 1] [5 1] [3 2] [2 1] [4 1] [5 2] [4 1] [5 1] [1 1] [2 1] [1 1] [2 1] [3 1] [5 1]]
(trampoline (letfn [(continue [n s brk] #(forloop (inc n) s brk)) (forloop [n s break] (if (< n 100) (if (zero? (rem n 4)) (continue n s break) (if (= n 13) #(break (str s n)) (continue n (str s n ", ") break))) #(break s)))] (forloop 1 "" identity)))
"1, 2, 3, 5, 6, 7, 9, 10, 11, 13"
(let [g [1 5 3 3 2 4 5 5 4 5 1 2 1 2 3 5] gs (sort g) [v x c] (reduce (fn [[v x c] y] (if (= x y) [v x (inc c)] [(conj v [x c]) y 1])) [[] (first gs) 1] (rest gs))] (conj v [x c]))
[[1 3] [2 3] [3 3] [4 2] [5 5]]
(->> [[8592 8703] [9027 9032] [9036 9037] [9039 9040] [9043 9044] [9046 9047] [9166] [9650] [9654] [9660] [9664] [9735 9736] [10132] [10136 10159] [10161 10174] [10224 10239] [10496 10538] [10541 10569] [10578 10619] [11008 11025]] (mapcat #(apply (fn ([x] [x]) ([x y] (range x (inc y)))) %)) (map char) (apply str))
"←↑→↓↔↕↖↗↘↙↚↛↜↝↞↟↠↡↢↣↤↥↦↧↨↩↪↫↬↭↮↯↰↱↲↳↴↵↶↷↸↹↺↻↼↽↾↿⇀⇁⇂⇃⇄⇅⇆⇇⇈⇉⇊⇋⇌⇍⇎⇏⇐⇑⇒⇓⇔⇕⇖⇗⇘⇙⇚⇛⇜⇝⇞⇟⇠⇡⇢⇣⇤⇥⇦⇧⇨⇩⇪⇫⇬⇭⇮⇯⇰⇱⇲⇳⇴⇵⇶⇷⇸⇹⇺⇻⇼⇽⇾⇿⍃⍄⍅⍆⍇⍈⍌⍍⍏⍐⍓⍔⍖⍗⏎▲▶▼◀☇☈➔➘➙➚➛➜➝➞➟➠➡➢➣➤➥➦➧➨➩➪➫➬➭➮➯➱➲➳➴➵➶➷➸➹➺➻➼➽➾⟰⟱⟲⟳⟴⟵⟶⟷⟸⟹⟺⟻⟼⟽⟾⟿⤀⤁⤂⤃⤄⤅⤆⤇⤈⤉⤊⤋⤌⤍⤎⤏⤐⤑⤒⤓⤔⤕⤖⤗⤘⤙⤚⤛⤜⤝⤞⤟⤠⤡⤢⤣⤤⤥⤦⤧⤨⤩⤪⤭⤮⤯⤰⤱⤲⤳⤴⤵⤶⤷⤸⤹⤺⤻⤼⤽⤾⤿⥀⥁⥂⥃⥄⥅⥆⥇⥈⥉⥒⥓⥔⥕⥖⥗⥘⥙⥚⥛⥜⥝⥞⥟⥠⥡⥢⥣⥤⥥⥦⥧⥨⥩⥪⥫⥬⥭⥮⥯⥰⥱⥲⥳⥴⥵⥶⥷⥸⥹⥺⥻⬀⬁⬂⬃⬄⬅⬆⬇⬈⬉⬊⬋⬌⬍⬎⬏⬐⬑"
(count (->> [[8592 8703] [9027 9032] [9036 9037] [9039 9040] [9043 9044] [9046 9047] [9166] [9650] [9654] [9660] [9664] [9735 9736] [10132] [10136 10159] [10161 10174] [10224 10239] [10496 10538] [10541 10569] [10578 10619] [11008 11025]] (mapcat #(apply (fn ([x] [x]) ([x y] (range x (inc y)))) %)) (map char) (apply str)))
320
(def ddr (fn [] (->> [[8592 8703] [9027 9032] [9036 9037] [9039 9040] [9043 9044] [9046 9047] [9166] [9650] [9654] [9660] [9664] [9735 9736] [10132] [10136 10159] [10161 10174] [10224 10239] [10496 10538] [10541 10569] [10578 10619] [11008 11025]] (mapcat #(apply (fn ([x] [x]) ([x y] (range x (inc y)))) %)) (map (comp symbol str char)) rand-nth)))
#'user/ddr