Last active
August 29, 2015 14:07
-
-
Save guilleiguaran/b517167c3cd97fab6cb9 to your computer and use it in GitHub Desktop.
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 balance(chars: List[Char]): Boolean = { | |
def balanceIter(chars: List[Char], count: Int) : Boolean = | |
if(count < 0) false | |
else if(chars.isEmpty) count == 0 | |
else if(chars.head == '(') balanceIter(chars.tail, count + 1) | |
else if(chars.head == ')') balanceIter(chars.tail, count - 1) | |
else balanceIter(chars.tail, count) | |
balanceIter(chars, 0) | |
} |
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 || coins.isEmpty) 0 | |
else if(money == 0) 1 | |
else countChange(money - coins.head, coins) + countChange(money, coins.tail) | |
} |
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 pascal(c: Int, r: Int): Int = { | |
if(c == 0 || r == 0 || c == r) 1 | |
else pascal(c - 1, r - 1) + pascal(c, r - 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment