ProjectRuler-9

来源:互联网 发布:unity3d fbx 层次 编辑:程序博客网 时间:2024/05/14 09:32
#A Pythagorean triplet is a set of three natural numbers, a  b  c, for which,#a2 + b2 = c2#For example, 32 + 42 = 9 + 16 = 25 = 52.#There exists exactly one Pythagorean triplet for which a + b + c = 1000.#Find the product abc.#answer: 31875000def pythagorean  flag = false  for a in (1..1000)    for b in (1..1000)      c = 1000-a-b      if(a**2+b**2 == c**2)        puts a, b, c, a*b*c        flag = true        break      end    end    break if flag  endendpythagorean