Created
February 1, 2018 03:24
-
-
Save junichiro/21a1c21761b17739c3b7c418bd313478 to your computer and use it in GitHub Desktop.
会社で少し盛り上がった Project Euler をやってみる 009 ref: https://qiita.com/junichiro/items/51d23139d469d1196c2e
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
a^2 + b^2 = c^2 |
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 Problem9: | |
def main(self, total): | |
for a in range(1, total - 1): | |
for b in range(a + 1, int((total - a) / 2) + 1): | |
c = total - a - b | |
if c ** 2 == a ** 2 + b ** 2: | |
return a * b * c | |
if __name__ == '__main__': | |
total = 1000 | |
if len(sys.argv) == 2: | |
total = int(sys.argv[1]) | |
p = Problem9() | |
print(p.main(total)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment