Created
August 23, 2014 16:27
-
-
Save luc99a/bb808b997df3904f2412 to your computer and use it in GitHub Desktop.
Pascal triangle generator in Python
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 pascal(col, row): | |
if col == 0 or col == row: | |
return 1 | |
return pascal(col - 1, row - 1) + pascal(col, row - 1) | |
col = 0 | |
row = 0 | |
line = [] | |
totallines = 0 | |
while totallines < 20: | |
line.append(pascal(col, row)) | |
if row == col: | |
row += 1 | |
col = 0 | |
print " ".join([str(i) for i in line]) | |
line = [] | |
totallines += 1 | |
else: | |
col += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment