Skip to content

Instantly share code, notes, and snippets.

@junichiro
Last active February 9, 2018 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junichiro/fe7a6804ab7d3878899bfbbd5b26b0af to your computer and use it in GitHub Desktop.
Save junichiro/fe7a6804ab7d3878899bfbbd5b26b0af to your computer and use it in GitHub Desktop.
会社で少し盛り上がった Project Euler をやってみる 015 ref: https://qiita.com/junichiro/items/76c0bf6ab32cb5121857
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