Skip to content

Instantly share code, notes, and snippets.

@rewonc
Created September 22, 2014 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rewonc/d2c4c2b857ed1800707d to your computer and use it in GitHub Desktop.
Save rewonc/d2c4c2b857ed1800707d to your computer and use it in GitHub Desktop.
Pascal's triangle in scala
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