Skip to content

Instantly share code, notes, and snippets.

@dinukadev
Last active June 11, 2020 21:39
Show Gist options
  • Save dinukadev/ea937045eb1e830475690ac440516508 to your computer and use it in GitHub Desktop.
Save dinukadev/ea937045eb1e830475690ac440516508 to your computer and use it in GitHub Desktop.
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