9: Special Pythagorean Triplet#

Description

Submit your answer

Your Solution#

Lunch this notebook and try to create your own solution!

Tip: look for the launch button (🚀) in the top right corner!

def problem9(N):  # N = a + b + c
    # Try your solution here
    return solution

# Testing:
unittest.main(argv=[''], verbosity=2,exit=False)

# Printing Project Euler Solution
# print(problem9(1_000))

My solution#

Spoiler Alert!!

See my solution bellow

def problem9(N):  # N = a + b + c
    
    for a in range(1, N+1):
        for b in range(a, N+1):
            c = N - a - b

            # Check if it is Pythagorean Triplet
            if (a*a + b*b == c*c):
                return a*b*c  
    return None

# Testing
unittest.main(argv=[''], verbosity=2,exit=False)

Add main question:

# Printing Project Euler Solution
print(problem9(1_000))
31875000