Created
August 1, 2016 19:27
-
-
Save oluies/516a38464534efcde342c22d19dd8d59 to your computer and use it in GitHub Desktop.
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
fun pascal(c: Int, r: Int): Int { | |
require(c>=0,{"column must be larger than zero"}) | |
require(r>=0,{"row must be larger than zero"}) | |
return when { | |
r == 0 -> 1 | |
r == 1 -> 1 | |
c == 0 -> 1 | |
c == r -> 1 | |
else -> pascal(c - 1, r - 1) + pascal(c, r - 1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment