Created
July 16, 2013 22:33
-
-
Save behaghel/6015790 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
%s should %s be balanced".format(s, | |
if (!expected) "NOT" else "")) | |
testBalance("(if (zero? x) max (/ 1 x))") | |
testBalance("I told him (that it's not (yet) done)." + | |
"(But he wasn’t listening)") | |
testBalance(":-)", expected = false) | |
testBalance("())(", expected = false) | |
} | |
/** | |
* Exercise 1 | |
*/ | |
def pascal(c: Int, r: Int): Int = { | |
require(c >= 0 && r >= 0, | |
"only positive coord please (%d, %d)".format(c, r)) | |
require(c <= r, | |
("the number of columns of row %d is exactly %d," + | |
"column %d is out sorry (starting from 0)").format(r,r+1,c)) | |
(c, (r - 1)) match { | |
case (_, x) if x < 1 => 1 | |
case (0, _) => 1 | |
case (x, y) if x > y => 1 | |
case (x, y) => pascal(x - 1, y) + pascal(x, y) | |
} | |
} | |
/** | |
* Exercise 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment