Last active
February 9, 2018 00:36
-
-
Save junichiro/fe7a6804ab7d3878899bfbbd5b26b0af to your computer and use it in GitHub Desktop.
会社で少し盛り上がった Project Euler をやってみる 015 ref: https://qiita.com/junichiro/items/76c0bf6ab32cb5121857
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
import sys | |
class Problem15: | |
def main(self, n): | |
tensor = [list(range(n + 1)) for i in range(n + 1)] | |
for i in range(n + 1): | |
for j in range(n + 1): | |
if i > 0 and j > 0: | |
tensor[i][j] = tensor[i-1][j] + tensor[i][j-1] | |
elif i > 0: | |
tensor[i][j] = tensor[i-1][j] | |
elif j > 0: | |
tensor[i][j] = tensor[i][j-1] | |
else: | |
tensor[i][j] = 1 | |
print(tensor[n][n]) | |
if __name__ == '__main__': | |
num = 20 | |
if len(sys.argv) == 2: | |
num = sys.argv[1] | |
p = Problem15() | |
p.main(int(num)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment