-
Notifications
You must be signed in to change notification settings - Fork 0
/
p009.jl
32 lines (23 loc) · 829 Bytes
/
p009.jl
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
#=
Special Pythagorean triplet
Problem 9
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a^2 + b^2 = c^2
For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
=#
# FOR DEEPER ANALYSIS SEE:
# https://math.stackexchange.com/questions/423196/derivation-of-pythagorean-triple-general-solution-starting-point
# Also note that pythagorean fomula for natural numbers a,b,c is a diophantine equation (basically, an equation where you want to find the integer solutions)
# easy approach: clearly any a,b,c must be <1000. So just loop
for c=1:1000
for b=1:c-1
for a = 1:b-1
if (a^2 + b^2 == c^2) & (a + b + c == 1000)
abc = a*b*c
print("a=$a, b=$b, c=$c \n product a*b*c=$abc \n")
end
end
end
end