Skip to content

Instantly share code, notes, and snippets.

@LauJensen
Created May 14, 2010 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LauJensen/400896 to your computer and use it in GitHub Desktop.
Save LauJensen/400896 to your computer and use it in GitHub Desktop.
(defn knapsack_count
[sack space]
(if (or (empty? sack) (< space 0))
0
(if (= space 0)
1
(+
(knapsack_count (next sack) space)
(knapsack_count sack (- space (first sack)))))))
(println (knapsack_count [1 2 5 10 20 50 100 200] 200))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment