Generating unique, ordered Pythagorean triplets

前端 未结 19 1307
借酒劲吻你
借酒劲吻你 2020-11-29 16:57

This is a program I wrote to calculate Pythagorean triplets. When I run the program it prints each set of triplets twice because of the if statement. Is there any way I can

19条回答
  •  旧时难觅i
    2020-11-29 17:50

    I juste extended Kyle Gullion 's answer so that triples are sorted by hypothenuse, then longest side.

    It doesn't use numpy, but requires a SortedCollection (or SortedList) such as this one

    def primitive_triples():
    """ generates primitive Pythagorean triplets xtriple[1]: # ensure x

    the code is available in the math2 module of my Python library. It is tested against some series of the OEIS (code here at the bottom), which just enabled me to find a mistake in A121727 :-)

提交回复
热议问题