Last active
August 29, 2015 14:21
-
-
Save ztellman/903ddc5e1c32956df8ec to your computer and use it in GitHub Desktop.
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
(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