Automatic commit performed through alias...
This commit is contained in:
44
problems/009_problem/009_problem.py
Normal file
44
problems/009_problem/009_problem.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# # Problem 9:
|
||||
#
|
||||
# [Euler Project #9](https://projecteuler.net/problem=9)
|
||||
#
|
||||
#
|
||||
#
|
||||
# >A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
|
||||
# a2 + b2 = c2
|
||||
#
|
||||
# >For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
|
||||
#
|
||||
# >There exists exactly one Pythagorean triplet for which a + b + c = 1000.
|
||||
# Find the product abc.
|
||||
#
|
||||
#
|
||||
#
|
||||
# ---
|
||||
import os
|
||||
import pprint
|
||||
import time # Typically imported for sleep function, to slow down execution in terminal.
|
||||
import typing
|
||||
import decorators # Typically imported to compute execution duration of functions.
|
||||
import math
|
||||
import numpy
|
||||
|
||||
def get_c(a,b):
|
||||
c = math.sqrt(a*a+b*b)
|
||||
return c
|
||||
|
||||
def check_constraint(a,b,c,limit):
|
||||
return (a+b+c)==limit
|
||||
|
||||
exit=False
|
||||
for a in range(1,1000):
|
||||
for b in range(a,1000):
|
||||
c = get_c(a,b)
|
||||
if check_constraint(a,b,c,1000):
|
||||
#print(a,b,c)
|
||||
#print(not_done)
|
||||
exit=True
|
||||
break
|
||||
if exit:
|
||||
break
|
||||
print(a,b,c,a+b+c,a*b*c)
|
||||
Reference in New Issue
Block a user