Created
October 7, 2015 08:21
-
-
Save harunyasar/6bfdaaea7aa39ccb3e9d to your computer and use it in GitHub Desktop.
Pascal Triangle
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(n): | |
if n == 1: | |
return [1] | |
else: | |
p_line = pascal(n - 1) | |
line = [p_line[i] + p_line[i + 1] for i in range(len(p_line) - 1)] | |
line.insert(0, 1) | |
line += [1] | |
return line | |
print pascal(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment