triplets_pythagoriciens.py

Created by nicolas-patrois

Created on April 26, 2018

348 Bytes

Déroule les triplets pythagoriciens primitifs jusqu’à la dimension de l’hypoténuse donnée en entrée.


def triplets(m):
 A=[[1,2,2],[2,1,2],[2,2,3]]
 B=[[-1,1,2],[-2,1,2],[-2,2,3]]
 C=[[1,-2,2],[2,-1,2],[2,-2,3]]
 T=[4,3,5]
 l=[T]

 while l:
  n=[]
  for t in l:
   for M in (A,B,C):
    N=[sum([l[j]*t[j] for j in range(len(M))]) for l in M]
    if N[2]<=m:
     n.append(N)
     print(" ".join(map(str,N)))
  l=list(n)