Last active
August 29, 2015 14:27
-
-
Save joegiralt/f4d5a04ebd77c26c362b to your computer and use it in GitHub Desktop.
Project Euler 9
This file contains hidden or 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
def special_pythagorean_triplet(num) | |
(1..(num/2)).to_a.combination(3).to_a.each do |set| | |
sort_set = set.sort! | |
triplet = (sort_set[0] ** 2 + sort_set[1]**2) == sort_set[2]**2 | |
equals_1000 = (sort_set.inject(:+) == num) | |
if triplet && equals_1000 | |
answer = sort_set.inject(:*) | |
else | |
answer = "no special triplet" | |
end | |
end | |
puts "********************************" | |
puts answer | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment