Skip to content

Instantly share code, notes, and snippets.

@ztellman
Last active August 29, 2015 14:21
Show Gist options
  • Save ztellman/903ddc5e1c32956df8ec to your computer and use it in GitHub Desktop.
Save ztellman/903ddc5e1c32956df8ec to your computer and use it in GitHub Desktop.
(defn possible-shrinks [s]
(let [cnt (count s)]
(concat
(->> (iterate #(* % 2) 1)
(take-while #(< % cnt))
reverse
(map #(drop % s)))
(->> (iterate #(* % 2) 1)
(take-while #(< % cnt))
(map #(take % s)))
(map
(fn [n]
(concat
(take n s)
(drop (inc n) s)))
(range (count s))))))
(defn minimal-shrink [test s]
(if-let [shrunk (loop [s (possible-shrinks s)]
(cond
(empty? s)
nil
(test (first s))
(first s)
:else
(recur (rest s))))]
(recur test shrunk)
s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment