mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-19 19:03:02 +08:00
snake_case all the things
This commit is contained in:
15
project_euler/problem_09/sol1.py
Normal file
15
project_euler/problem_09/sol1.py
Normal file
@ -0,0 +1,15 @@
|
||||
from __future__ import print_function
|
||||
# Program to find the product of a,b,c which are Pythagorean Triplet that satisfice the following:
|
||||
# 1. a < b < c
|
||||
# 2. a**2 + b**2 = c**2
|
||||
# 3. a + b + c = 1000
|
||||
|
||||
print("Please Wait...")
|
||||
for a in range(300):
|
||||
for b in range(400):
|
||||
for c in range(500):
|
||||
if(a < b < c):
|
||||
if((a**2) + (b**2) == (c**2)):
|
||||
if((a+b+c) == 1000):
|
||||
print(("Product of",a,"*",b,"*",c,"=",(a*b*c)))
|
||||
break
|
18
project_euler/problem_09/sol2.py
Normal file
18
project_euler/problem_09/sol2.py
Normal file
@ -0,0 +1,18 @@
|
||||
"""A Pythagorean triplet is a set of three natural numbers, for which,
|
||||
a^2+b^2=c^2
|
||||
Given N, Check if there exists any Pythagorean triplet for which a+b+c=N
|
||||
Find maximum possible value of product of a,b,c among all such Pythagorean triplets, If there is no such Pythagorean triplet print -1."""
|
||||
#!/bin/python3
|
||||
|
||||
product=-1
|
||||
d=0
|
||||
N = int(raw_input())
|
||||
for a in range(1,N//3):
|
||||
"""Solving the two equations a**2+b**2=c**2 and a+b+c=N eliminating c """
|
||||
b=(N*N-2*a*N)//(2*N-2*a)
|
||||
c=N-a-b
|
||||
if c*c==(a*a+b*b):
|
||||
d=(a*b*c)
|
||||
if d>=product:
|
||||
product=d
|
||||
print(product)
|
Reference in New Issue
Block a user