Created
August 10, 2014 13:21
-
-
Save sigmavirus24/44885b92ce00e105b92e to your computer and use it in GitHub Desktop.
Pascal's 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
1 | |
1 1 | |
1 2 1 | |
1 3 3 1 | |
1 4 6 4 1 | |
1 5 10 10 5 1 | |
1 6 15 20 15 6 1 | |
1 7 21 35 35 21 7 1 | |
1 8 28 56 70 56 28 8 1 |
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
# Source: https://twitter.com/raymondh/status/498316311013777408 | |
from __future__ import print_function | |
from math import factorial as f | |
def main(): | |
for n in range(9): | |
print( | |
''.join( | |
'%4d' % (f(n)/f(n-k)/f(k)) for k in range(0, n + 1) | |
).center(40) | |
) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
funny