毕达哥拉斯三重发生器
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了毕达哥拉斯三重发生器相关的知识,希望对你有一定的参考价值。
Very quick and dirty Pythagorean triples generator
#!/bin/ruby # author: Lukasz Korecki, student no: 0617836 # purpose: simple program generating Pythagorian triples # Vars: given_number = 60 m = 1 # Number definitions using the article from wikipedia: # http://en.wikipedia.org/wiki/Pythagorean_triple#Other_formulas_for_generating_triples # a = m*2 + 1 b = (m*2) * (m + 1) c = ((m*2) * (m + 1)) + 1 sum = a + b + c # Output and formatting sep = " | " puts "Your max value is " + given_number.to_s puts sep+"small"+sep+"medium"+sep+"large"+ sep + "sum" + sep puts "-" * 80 # Main loop calculating the numbers and outputs while c < given_number m +=1 puts sep + a.to_s + sep+ b.to_s + sep +c.to_s + sep + sum.to_s + sep a = m*2 + 1 b = (m*2) * (m + 1) c = ((m*2) * (m + 1)) + 1 sum = a + b +c end
以上是关于毕达哥拉斯三重发生器的主要内容,如果未能解决你的问题,请参考以下文章