Skip to content

Instantly share code, notes, and snippets.

@myokoym
Created August 17, 2012 15:10
Show Gist options
  • Save myokoym/3379700 to your computer and use it in GitHub Desktop.
Save myokoym/3379700 to your computer and use it in GitHub Desktop.
Problem039
#! ruby
max = 1000
ans = (0..max).to_a.fill(0)
1.upto(max) do |a|
a.upto(max) do |b|
c = Math.hypot(a, b)
next unless c % 1 == 0
p = a + b + c
next unless p <= max
p p
ans[p] += 1
end
end
p ans.max
p ans.rindex {|v| v == ans.max }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment