Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def makeChange(in: Int): Map[Int, Int] = {
- def nextCoin(cur: Int) = cur match {
- case 25 => 10;
- case 10 => 5;
- case 5 => 1;
- case _ => throw new Exception(βBlah!β);
- }
- def inner(remaining: Int, coinVal: Int): Int = {
- if (coinVal == 1)
- 1
- else {
- val maxCoins = remaining / coinVal;
- val nextVal = nextCoin(coinVal)
- (0 to maxCoins) map (inner(remaining - _ * coinVal, nextVal)) sum
- }
- }
- inner(in, 25)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement