Created
July 25, 2011 19:24
-
-
Save mjg123/1104951 to your computer and use it in GitHub Desktop.
Why can't I recur here?
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 calculate | |
"A list of coin-values from coins, which sum to target" | |
[coins target] | |
(let [coin (max-coin coins target)] | |
(cond | |
(not coin) (js-alert "No solution") | |
(= coin target) (list coin) | |
(< coin target) (cons coin (recur coins (- target coin)))))) |
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 calculate | |
"Make the value of target out of values in the list of coins" | |
([coins target] | |
(reverse (calculate coins target (list)))) | |
([coins target so-far] | |
(let [coin (max-coin coins target)] | |
(cond | |
(not coin) (js-alert "No solution") | |
(= coin target) (cons coin so-far) | |
(< coin target) (recur coins (- target coin) (cons coin so-far)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AssertionError Assert failed: Can't recur here