A Pythagorean triplet is a set of three natural numbers, a
b
c, for which,
For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
Source code in my favorite programming language: Ruby
@a =3
@b = 4
def square_em()
@asq = (@a ** 2)
@bsq = (@b **2 )
@csq = @asq + @bsq
end
def c_is_int()
square_em()
@c = Math.sqrt(@csq)
unless (@c-@c.to_i == 0)
then p “C not an Integer! Iterating A & B”
@a += 1
@b += 2
square_em()
c_is_int()
end
end
sum =0
while ( @a < @b && sum < 1000) do
c_is_int()
sum = @a+@b+@c
prod = @a*@b*@c
p “A:#{@a} B:#{@b} C:#{@c}”
p “Sum of a + b + c: #{sum}”
p “Prod of a * b *c #{prod}”
p “”
#test code
#exit;
@a += 1
@b+= 1
@asq = (@a ** 2)
@bsq = (@b **2 )
@csq = @asq + @bsq
end




