-
-
Save jbochi/4128413 to your computer and use it in GitHub Desktop.
Pascal triangule using recursion
This file contains 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 print_pascal_triangle(n_lines): | |
for row in xrange(n_lines): | |
for col in xrange(row + 1): | |
print pascal(row, col), | |
def pascal(row, col): | |
if col == 0 or row == col: | |
return 1 | |
else: | |
return pascal(row - 1, col) + pascal(row - 1, col - 1) | |
print_pascal_triangle(5) | |
# 1 | |
# 1 1 | |
# 1 2 1 | |
# 1 3 3 1 | |
# 1 4 6 4 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment