Hunt primitive Pythagorean triples
#!/usr/bin/python3 import sys,math n = int(sys.argv[1]) print([(x,y,z) for x in range(1,n+1) for y in range(x,n+1,1) for z in range(y,n+1,1) if x**2 + y**2 == z**2 and math.gcd(x,y) == 1])
Not just a #Python speedup, but a jailbreak from the space-time continuum….
teresita:Desktop$ /usr/bin/time -f ‘%e seconds’ python3 /usr/local/games/pythag 1000 >/dev/null
116.26 seconds
teresita:Desktop$ sudo apt install pypy3
teresita:Desktop$ /usr/bin/time -f ‘%e seconds’ pypy3 /usr/local/games/pythag 1000 >/dev/null
0.27 seconds
