Skip to content

Commit

Permalink
Merge pull request #42 from upakarp/pythagorean_triplet
Browse files Browse the repository at this point in the history
Pythagorean triplet
  • Loading branch information
ademclk authored Aug 23, 2022
2 parents 159d3df + dae4072 commit 5115e85
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions challenges/pythagorean_triplet/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def pythagorean_triplet(num):
for a in range(1, num // 3 + 1):
for b in range(a+1, num // 2 + 1):
c = num - a - b
if a**2 + b**2 == c**2:
return (a, b, c)
return (0, 0, 0)

print(pythagorean_triplet(1000))
assert (200, 375, 425) == pythagorean_triplet(1000)

0 comments on commit 5115e85

Please sign in to comment.