Skip to content

Instantly share code, notes, and snippets.

@jaley
jaley / gist:1981322
Created March 5, 2012 21:47
Doug's solution, map-reduced
(defn sample-mr [l]
(reduce (fn [x [y i]] (if (< (/ i (inc i)) (rand)) y x))
nil
(map vector l (iterate inc 0))))
@jaley
jaley / curly.clj
Created March 1, 2012 18:30
Remove text surrounded by curly braces.
(defn remove-curlied
[^String text]
(let [sb (StringBuilder.)
end (int (count text))]
(loop [state (int 0)
pos (int 0)]
(cond
(= pos end) (.toString sb)
(= (int (.charAt text pos)) (int \{)) (recur (inc state) (inc pos))
(= (int (.charAt text pos)) (int \})) (recur (dec state) (inc pos))