Created
September 15, 2015 22:20
-
-
Save cleure/3b99b9455ad7504368f9 to your computer and use it in GitHub Desktop.
Pascals Triangle
This file contains hidden or 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
import os, sys, math | |
def pascals_triangle(height): | |
data = [[1]] | |
width = 2 | |
for i in range(1, height): | |
row = [] | |
prev = 0 | |
for j in data[-1] + [0]: | |
row.append(prev + j) | |
prev = j | |
data.append(row) | |
width += 1 | |
return data | |
def main(): | |
print(pascals_triangle(8)) | |
sys.exit(0) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment