Skip to content

Instantly share code, notes, and snippets.

@masui
Created May 25, 2015 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masui/a9b9ea5d126048ef59b1 to your computer and use it in GitHub Desktop.
Save masui/a9b9ea5d126048ef59b1 to your computer and use it in GitHub Desktop.
a^2 + b^2 == c^2 かつ a+b+c=1000, a < b < c となる a, b, c を求める (流石にナイーブすぎて遅いバージョン)
(1..1000).each { |i|
(1..1000).each { |j|
(1..1000).each { |k|
next if j <= i
next if k <= j
next if i+j+k != 1000
puts "#{i}, #{j}, #{k}" if i*i + j*j == k*k
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment