-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem9.py
More file actions
131 lines (66 loc) · 1.68 KB
/
Problem9.py
File metadata and controls
131 lines (66 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 5 16:08:30 2025
@author: root
"""
from math import sqrt
def is_natural_num (n):
if (n % 1 == 0):
if (n >= 0):
return True
else:
return False
else:
return False
def solve_quad_formula (a,b,c):
if (b**2 - 4*a*c >= 0):
b1 = (-b + sqrt(b**2 - 4*a*c))/(2*a)
b2 = (-b - sqrt(b**2 - 4*a*c))/(2*a)
return [b1,b2]
else:
return 1
# a + b + c = 1000
# a^2 + b^2 = c^2
# a < b < c
# Solve for abc
# Find a,b,c
# Idea: Loop through different c's and find reciprocating a and b by solving
# the two equations
c = 1
while True:
d = 2
e = -2*(1000-c)
f = (1000-c)**2 - c**2
if (solve_quad_formula(d,e,f) != 1):
[b1, b2] = solve_quad_formula(d,e,f)
else:
c = c + 1
continue
if (is_natural_num(b1)):
b = b1
a1 = 1000-c-b1
if (is_natural_num(a1)):
a = a1
break
elif (is_natural_num(b2)):
b = b2
a2 = 1000-c-b2
if (is_natural_num(a2)):
a = a2
break
c = c+1
product = a*b*c
print(product)
# (1000 - c) - b = a
# sub into a^2+b^2=c^2
# ((1000-c)-b)^2 + b^2 = c^2
# (1000-c)^2 -2*(1000-c)*b + b^2 + b^2 = c^2
# 2b^2 - 2*(1000-c)*b + (1000-c)^2-c^2 = 0
# b1 = [ 2*(1000-c) + Sqrt ((2*(1000-c))^2 - (4*2*((1000-c)^2-c^2)))]/4
# b2 = [ 2*(1000-c) - Sqrt ((2*(1000-c))^2 - (4*2*((1000-c)^2-c^2)))]/4
# check b is a natural number else move onto next c
# Calculate a
# a1 = 1000-c-b1
# a2 = 1000-c-b2
# check a is a natural number