Created
July 21, 2013 22:11
-
-
Save siscia/6050217 to your computer and use it in GitHub Desktop.
support gist
This file contains 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 subset | |
([s] | |
(subset [] s)) | |
([tot r] | |
(if (seq r) | |
(lazy-cat | |
(subset (conj tot (first r)) (next r)) | |
(subset tot (next r))) | |
[tot]))) | |
(defn check-seq [num s] | |
(cond | |
(and | |
(seq s) | |
(= (apply + s) num)) s | |
:else false)) | |
(defn find-solutions [num s] | |
(let [solutions | |
(map #(check-seq num %) | |
(subset s))] | |
(filter boolean solutions))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment