Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
object PascalsTriangle extends App {
/**
* 1
* 1 1
* 1 2 1
* 1 3 3 1
* 1 4 6 4 1
*
*/
def pascalTriangle(col: Int, row: Int): Int = {
if(col<0 || row <0) throw new IllegalArgumentException("Values cannot be negative")
if (((col + row) == row) || col == row) return 1
pascalTriangle(col - 1, row - 1) + pascalTriangle(col, row - 1)
}
println(pascalTriangle(1, -2))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment