Let's get this out of the way: I already had a look at this answer here. My approach however is different. I'm leveraging the cantor pairing function and basically mapping the triplets as integers. the complete sequence is as follows:
1) iterate over (i,j) and adding the cantor(i,j) to an array as long as gcd(i,j) == 1 and i < j
2) sort smallest to largest
My rudimentary understanding would have me think that this should return an ordered set of primitive pythagorean triples, is that not so?
Here's the code:
def go(n):
tmpi = []
for i in range(1,n):
for j in range(n%2 +1,n,2):
if gcd(i,j) == 1:
if (i+j)%2 == 1:
if i < j:
tmpi.append(cantor(i,j))
tmpi.sort()
return tmpi
and the cantor function:
def cantor(x,y):
return int(0.5*(x+y)*(x+y+1)+y)
Am I missing something?
Edit:
With this additional code:
def lister(li):
tmp = []
for i in li:
tmp.append(list(retTrp(invCant(i))))
return tmp
def listi2(li):
for i in li:
i.sort()
def sorti(li):
return sorted(li, key=itemgetter(2))
def doall(n):
tmp = lister(go(n))
listi2(tmp)
return sorti(tmp)
The input:
doall(100)[99]
should return
[429, 460, 629]
but instead the above is returned when the input is
doall(100)[100]
Hence my question about the order.