Skip to content

Instantly share code, notes, and snippets.

@siscia
Created July 21, 2013 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save siscia/6050217 to your computer and use it in GitHub Desktop.
Save siscia/6050217 to your computer and use it in GitHub Desktop.
support gist
(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