Last active
December 15, 2015 12:48
-
-
Save vkobel/5262411 to your computer and use it in GitHub Desktop.
Simple scala function to compute the pascal triangle
This file contains hidden or 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
package week1 | |
object pascalTriangle { | |
def pascal(c: Int, r: Int): Int = { | |
if (r == 0 && c == 0) 1 | |
else if (c < 0 || c > r + 1) 0 | |
else pascal(c - 1, r - 1) + pascal(c, r - 1) | |
} //> pascal: (c: Int, r: Int)Int | |
pascal(10, 23) //> res0: Int = 1144066 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: make it tailrec