Skip to content

Instantly share code, notes, and snippets.

@joegiralt
Last active August 29, 2015 14:27
Show Gist options
  • Save joegiralt/f4d5a04ebd77c26c362b to your computer and use it in GitHub Desktop.
Save joegiralt/f4d5a04ebd77c26c362b to your computer and use it in GitHub Desktop.
Project Euler 9
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