Skip to content

Instantly share code, notes, and snippets.

@luc99a
Created August 23, 2014 16:27
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 luc99a/bb808b997df3904f2412 to your computer and use it in GitHub Desktop.
Save luc99a/bb808b997df3904f2412 to your computer and use it in GitHub Desktop.
Pascal triangle generator in Python
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