# Posted By

lukaszkorecki on 02/24/08

# Statistics

Viewed 355 times
Favorited by 1 user(s)

# Pythagorean triples generator

/ Published in: Ruby  Very quick and dirty Pythagorean triples generator

Copy this code and paste it in your HTML
`#!/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 + 1b = (m*2) * (m + 1)c = ((m*2) * (m + 1)) + 1sum = a + b + c  # Output and formattingsep = "\t|\t"puts "Your max value is " + given_number.to_sputs sep+"small"+sep+"medium"+sep+"large"+ sep + "sum" + sepputs "-" * 80 # Main loop calculating the numbers and outputswhile 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` Subscribe to comments