Skip to content

Instantly share code, notes, and snippets.

@telliott99
Created April 21, 2021 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save telliott99/1d41015073e37a973afae4671b517007 to your computer and use it in GitHub Desktop.
Save telliott99/1d41015073e37a973afae4671b517007 to your computer and use it in GitHub Desktop.
import math, operator
N = 1000
R = range(2,N)
D = dict()
for x in R:
D[x] = x**2
def is_square(x):
sr = int(x**0.5)
if sr**2 == x:
return sr
L = list()
for i in R:
for j in range(2,i):
if not math.gcd(i,j) == 1:
continue
v = i**2 + j**2
result = is_square(v)
if result:
L.append((j,i,result))
#-----------------------
def factors(x):
rL = list()
top = int(x**0.5)
for i in range(1,top):
if x % i == 0:
j = x//i
rL.append((i,j))
rL.append((top,x//top))
return rL
def mn(t):
a,b,c = t
# make sure b is even
if not b % 2 == 0:
a,b = b,a
p = b//2
fL = factors(p)
#print(p,fL)
for x,y in fL:
diff = y**2 - x**2
# we may have switched a,b
if a == diff:
return (x,y)
if b == diff:
return (x,y)
rL = list()
for t in L:
rL.append((mn(t),t))
rL.sort()
for t in rL:
print(t)
'''
> p3 pyth.py
((1, 2), (3, 4, 5))
((1, 4), (8, 15, 17))
((1, 6), (12, 35, 37))
((1, 8), (16, 63, 65))
((1, 10), (20, 99, 101))
((1, 12), (24, 143, 145))
((1, 14), (28, 195, 197))
((1, 16), (32, 255, 257))
((1, 18), (36, 323, 325))
((1, 20), (40, 399, 401))
((1, 22), (44, 483, 485))
((1, 24), (48, 575, 577))
((1, 26), (52, 675, 677))
((1, 28), (56, 783, 785))
((1, 30), (60, 899, 901))
((2, 3), (5, 12, 13))
((2, 5), (20, 21, 29))
((2, 7), (28, 45, 53))
((2, 9), (36, 77, 85))
((2, 11), (44, 117, 125))
((2, 13), (52, 165, 173))
((2, 15), (60, 221, 229))
((2, 17), (68, 285, 293))
((2, 19), (76, 357, 365))
((2, 21), (84, 437, 445))
((2, 23), (92, 525, 533))
((2, 25), (100, 621, 629))
((2, 27), (108, 725, 733))
((2, 29), (116, 837, 845))
((2, 31), (124, 957, 965))
((3, 4), (7, 24, 25))
((3, 8), (48, 55, 73))
((3, 10), (60, 91, 109))
((3, 14), (84, 187, 205))
((3, 16), (96, 247, 265))
((3, 20), (120, 391, 409))
((3, 22), (132, 475, 493))
((3, 26), (156, 667, 685))
((3, 28), (168, 775, 793))
((4, 5), (9, 40, 41))
((4, 7), (33, 56, 65))
((4, 9), (65, 72, 97))
((4, 11), (88, 105, 137))
((4, 13), (104, 153, 185))
((4, 15), (120, 209, 241))
((4, 17), (136, 273, 305))
((4, 19), (152, 345, 377))
((4, 21), (168, 425, 457))
((4, 23), (184, 513, 545))
((4, 25), (200, 609, 641))
((4, 27), (216, 713, 745))
((4, 29), (232, 825, 857))
((4, 31), (248, 945, 977))
((5, 6), (11, 60, 61))
((5, 8), (39, 80, 89))
((5, 12), (119, 120, 169))
((5, 14), (140, 171, 221))
((5, 16), (160, 231, 281))
((5, 18), (180, 299, 349))
((5, 22), (220, 459, 509))
((5, 24), (240, 551, 601))
((5, 26), (260, 651, 701))
((5, 28), (280, 759, 809))
((5, 32), (320, 999, 1049))
((6, 7), (13, 84, 85))
((6, 11), (85, 132, 157))
((6, 13), (133, 156, 205))
((6, 17), (204, 253, 325))
((6, 19), (228, 325, 397))
((6, 23), (276, 493, 565))
((6, 25), (300, 589, 661))
((6, 29), (348, 805, 877))
((6, 31), (372, 925, 997))
((7, 8), (15, 112, 113))
((7, 10), (51, 140, 149))
((7, 12), (95, 168, 193))
((7, 16), (207, 224, 305))
((7, 18), (252, 275, 373))
((7, 20), (280, 351, 449))
((7, 22), (308, 435, 533))
((7, 24), (336, 527, 625))
((7, 26), (364, 627, 725))
((7, 30), (420, 851, 949))
((7, 32), (448, 975, 1073))
((8, 9), (17, 144, 145))
((8, 11), (57, 176, 185))
((8, 13), (105, 208, 233))
((8, 15), (161, 240, 289))
((8, 17), (225, 272, 353))
((8, 19), (297, 304, 425))
((8, 21), (336, 377, 505))
((8, 23), (368, 465, 593))
((8, 25), (400, 561, 689))
((8, 27), (432, 665, 793))
((8, 29), (464, 777, 905))
((8, 31), (496, 897, 1025))
((9, 10), (19, 180, 181))
((9, 14), (115, 252, 277))
((9, 16), (175, 288, 337))
((9, 20), (319, 360, 481))
((9, 22), (396, 403, 565))
((9, 26), (468, 595, 757))
((9, 28), (504, 703, 865))
((9, 32), (576, 943, 1105))
((10, 11), (21, 220, 221))
((10, 13), (69, 260, 269))
((10, 17), (189, 340, 389))
((10, 19), (261, 380, 461))
((10, 21), (341, 420, 541))
((10, 23), (429, 460, 629))
((10, 27), (540, 629, 829))
((10, 29), (580, 741, 941))
((10, 31), (620, 861, 1061))
((10, 33), (660, 989, 1189))
((11, 12), (23, 264, 265))
((11, 14), (75, 308, 317))
((11, 16), (135, 352, 377))
((11, 18), (203, 396, 445))
((11, 20), (279, 440, 521))
((11, 24), (455, 528, 697))
((11, 26), (555, 572, 797))
((11, 28), (616, 663, 905))
((11, 30), (660, 779, 1021))
((11, 32), (704, 903, 1145))
((12, 13), (25, 312, 313))
((12, 17), (145, 408, 433))
((12, 19), (217, 456, 505))
((12, 23), (385, 552, 673))
((12, 25), (481, 600, 769))
((12, 29), (696, 697, 985))
((12, 31), (744, 817, 1105))
((13, 14), (27, 364, 365))
((13, 16), (87, 416, 425))
((13, 18), (155, 468, 493))
((13, 20), (231, 520, 569))
((13, 22), (315, 572, 653))
((13, 24), (407, 624, 745))
((13, 28), (615, 728, 953))
((13, 30), (731, 780, 1069))
((13, 32), (832, 855, 1193))
((13, 34), (884, 987, 1325))
((14, 15), (29, 420, 421))
((14, 17), (93, 476, 485))
((14, 19), (165, 532, 557))
((14, 23), (333, 644, 725))
((14, 25), (429, 700, 821))
((14, 27), (533, 756, 925))
((14, 29), (645, 812, 1037))
((14, 31), (765, 868, 1157))
((14, 33), (893, 924, 1285))
((15, 16), (31, 480, 481))
((15, 22), (259, 660, 709))
((15, 26), (451, 780, 901))
((15, 28), (559, 840, 1009))
((15, 32), (799, 960, 1249))
((16, 17), (33, 544, 545))
((16, 19), (105, 608, 617))
((16, 21), (185, 672, 697))
((16, 23), (273, 736, 785))
((16, 25), (369, 800, 881))
((16, 27), (473, 864, 985))
((16, 29), (585, 928, 1097))
((16, 31), (705, 992, 1217))
((17, 18), (35, 612, 613))
((17, 20), (111, 680, 689))
((17, 22), (195, 748, 773))
((17, 24), (287, 816, 865))
((17, 26), (387, 884, 965))
((17, 28), (495, 952, 1073))
((18, 19), (37, 684, 685))
((18, 23), (205, 828, 853))
((18, 25), (301, 900, 949))
((19, 20), (39, 760, 761))
((19, 22), (123, 836, 845))
((19, 24), (215, 912, 937))
((19, 26), (315, 988, 1037))
((20, 21), (41, 840, 841))
((20, 23), (129, 920, 929))
((21, 22), (43, 924, 925))
>
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment