RosettaCodeData/Task/Pythagorean-triples/Sidef/pythagorean-triples.sidef
2017-09-25 22:28:19 +02:00

21 lines
533 B
Text
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

func triples(limit) {
var primitive = 0
var civilized = 0
func oyako(a, b, c) {
(var perim = a+b+c) > limit || (
primitive++
civilized += int(limit / perim)
oyako( a - 2*b + 2*c, 2*a - b + 2*c, 2*a - 2*b + 3*c)
oyako( a + 2*b + 2*c, 2*a + b + 2*c, 2*a + 2*b + 3*c)
oyako(-a + 2*b + 2*c, -2*a + b + 2*c, -2*a + 2*b + 3*c)
)
}
oyako(3,4,5)
"#{limit} => (#{primitive} #{civilized})"
}
 
for n (1..Inf) {
say triples(10**n)
}