Skip to content

Instantly share code, notes, and snippets.

@demoth
Created September 23, 2013 17:21
Show Gist options
  • Save demoth/6673947 to your computer and use it in GitHub Desktop.
Save demoth/6673947 to your computer and use it in GitHub Desktop.
pascal triangle and recursive pascal function done in groovy
def pascal(col, row) {
assert col >= 0 && row >= 0 && col <= row
if (col == 0 || row == 1 || col == row)
return 1
return pascal(col - 1, row - 1) + pascal(col, row - 1)
}
def triangle(rows) {
assert rows >= 0
(0..rows).each { row ->
(0..row).each { col ->
print(pascal(col, row) + ' ')
}
println()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment