Last active
December 29, 2015 02:39
-
-
Save landau/7601550 to your computer and use it in GitHub Desktop.
Coins
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 count-change [money coins] | |
(cond | |
(= money 0) 1 | |
(or (< money 0) (empty? coins)) 0 | |
:else (+ | |
(count-change (- money (first coins)) coins) | |
(count-change money (rest coins))))) |
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
function countChange(money, coins) { | |
if (money === 0) return 1; | |
else if (money < 0 || coins.length < 1) return 0; | |
else countChange(money - coins[0], coins) + countChange(money, coins.slice(1)); | |
} |
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
def countChange(money: Int, coins: List[Int]): Int = { | |
if (money == 0) 1 | |
else if (money < 0 || coins.isEmpty) 0 | |
else countChange(money - coins.head, coins) + countChange(money, coins.tail) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment