Created
September 22, 2014 15:58
-
-
Save rewonc/d2c4c2b857ed1800707d to your computer and use it in GitHub Desktop.
Pascal's triangle in scala
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
def pascal(c: Int, r: Int): Int = { | |
if (c < 0 || r < 0 || c > r) throw new IllegalArgumentException("Column and row numbers must be 0 or greater. Column length must be lower than row length") else{ | |
if (c == 0 || 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