Skip to content

Instantly share code, notes, and snippets.

View djtrack16's full-sized avatar

Darius Liddell djtrack16

  • CareRev
View GitHub Profile
KENAI PENINSULA|AK: 203500
ANCHORAGE|AK: 295800
FAIRBANKS NORTH STAR|AK: 218200
JUNEAU|AK: 335700
KETCHIKAN GATEWAY|AK: 210500
KODIAK ISLAND|AK: 272900
JEFFERSON|AL: 130647
SHELBY|AL: 203576
TALLAPOOSA|AL: 108800
LAUDERDALE|AL: 116650
@djtrack16
djtrack16 / rankofPerm.clj
Created January 13, 2015 02:18
given a string and rank, find the permutation is at that index of the sorted permutations
(fn [s rank]
(let [n (count s) step (reduce * (range 1 n))]
(loop [i 0 s (sort s) acc '() r rank step step]
(let [index (quot r step)]
(if (= 1 (count s))
(clojure.string/join (concat acc s))
(recur (inc i)
(concat (take index s) (drop (inc index) s))
(concat acc [(nth s index)])
(- r (* index step))
@djtrack16
djtrack16 / gist:d8a24164f702e9f04142
Created January 13, 2015 02:17
all prime factors of n
(fn primeFactors
([n] (primeFactors n 2))
([n div]
(cond
(< n div) '()
(zero? (mod n div)) (cons div (lazy-seq (primeFactors (/ n div) div)))
:else (recur n (inc div)))))
@djtrack16
djtrack16 / parens.clj
Created January 13, 2015 02:16
all combos of well-formed parens of size O
(fn [o]
(let [f (fn q [s o c]
(set(remove #(or (coll? %) (nil? %))
(tree-seq
coll?
seq
(let[j (fn [sep coll] (clojure.string/join sep coll))
a (if (pos? o) (q (concat s "(") (dec o) (inc c)))
b (if (pos? c) (q (concat s ")") o (dec c)))]
(if (and (zero? o) (zero? c))