Skip to content

Instantly share code, notes, and snippets.

@vdupain
Created April 5, 2013 14:12
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 vdupain/5319563 to your computer and use it in GitHub Desktop.
Save vdupain/5319563 to your computer and use it in GitHub Desktop.
Exercise 1: Pascal’s Triangle
object pascal {
def pascal(c: Int, r: Int): Int = {
def loop(c: Int, r: Int): Int = {
if (c == r || c == 0) 1
else loop(c, r - 1) + loop(c - 1, r - 1)
}
loop(c, r)
}
def pascalTriangle() {
println("Pascal's Triangle")
for (row <- 0 to 10) {
for (col <- 0 to row)
print(pascal(col, row) + " ")
println()
}
}
pascalTriangle()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment