Last active
December 1, 2018 05:36
-
-
Save junpeitsuji/7c279f8e92fd3a5e3b5aba1e783934df to your computer and use it in GitHub Desktop.
パスカルの三角形をコンソール上で綺麗に書くpythonスクリプト
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
# coding: utf-8 | |
import scipy.misc as scm | |
# パスカルの三角形を生成 | |
print("") | |
print("") | |
print("") | |
n = 10 | |
a = 6 # ここで指定した値のところにアスタリスクがつく | |
for i in range(0,n+1): | |
print(" " * (3*n-3*i), end="") | |
for j in range(0,i+1): | |
#print(" " * (2), end="") | |
comb = scm.comb(i,j,exact=True) | |
if comb == a: | |
print("%5d*" % comb, end="") | |
else: | |
print("%5d " % comb, end="") | |
print("") | |
print("") | |
print("") | |
''' | |
# result: | |
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 | |
1 9 36 84 126 126 84 36 9 1 | |
1 10 45 120 210 252 210 120 45 10 1 | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment