Last active
June 11, 2020 21:39
-
-
Save dinukadev/ea937045eb1e830475690ac440516508 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
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