Created
May 27, 2011 06:33
-
-
Save johana-star/994758 to your computer and use it in GitHub Desktop.
Euler Project Problem #009
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Solution to Project Euler's ninth problem | |
# http://projecteuler.net/index.php?section=problems&id=9 | |
# Find the product of the Pythagorean triplets whose sum equals 1000. | |
def find_Pythagorean_triplet(number) | |
squares = (1..number).to_a.reverse | |
squares = squares.each_index {|s| squares[s] = squares[s]**2} | |
p squares | |
squares.each do |c| | |
squares.each do |b| | |
squares.each do |a| | |
if 0 == c - b - a then | |
if 1000 == Math.sqrt(a) + Math.sqrt(b) + Math.sqrt(c) then | |
product = Math.sqrt(a)*Math.sqrt(b)*Math.sqrt(c) | |
puts product | |
return product | |
end | |
end | |
end | |
end | |
end | |
end | |
find_Pythagorean_triplet(500) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment