Skip to content

Instantly share code, notes, and snippets.

@ghamarian
Created December 7, 2024 14:48
Show Gist options
  • Save ghamarian/2fa61565ceb8a67b20fdbf7fcff39e7e to your computer and use it in GitHub Desktop.
Save ghamarian/2fa61565ceb8a67b20fdbf7fcff39e7e to your computer and use it in GitHub Desktop.
def next_row(a):
return [0] + [a + b for a, b in zip(a, a[1:])] + [0]
def g(n):
lst = [[0, 1, 0]]
for _ in range(n):
lst.append(next_row(lst[-1]))
return lst
def print_pascal(pascal_lists):
longest_size = len(pascal_lists[-1])
for lst in pascal_lists:
current_length = len(lst)
content = " ".join([f"{item:^5}" for item in lst if item != 0])
print(f'{" " * ((longest_size - current_length)) *3 }{content}')
print_pascal(g(14))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment