Skip to content

Instantly share code, notes, and snippets.

@oluies
Created August 1, 2016 19:27
Show Gist options
  • Save oluies/516a38464534efcde342c22d19dd8d59 to your computer and use it in GitHub Desktop.
Save oluies/516a38464534efcde342c22d19dd8d59 to your computer and use it in GitHub Desktop.
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