Skip to content

Instantly share code, notes, and snippets.

@vkobel
Last active December 15, 2015 12:48
Show Gist options
  • Save vkobel/5262411 to your computer and use it in GitHub Desktop.
Save vkobel/5262411 to your computer and use it in GitHub Desktop.
Simple scala function to compute the pascal triangle
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
}
@vkobel
Copy link
Author

vkobel commented Mar 28, 2013

TODO: make it tailrec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment