Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/tasks/pythagorean-triples/oracle.py # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / tasks / pythagorean-triples / oracle.py` 19 lines ยท 787 bytes Raw Blame History 1 # Independent reference for "Pythagorean triples" (Python 3, standard library only). 2 # expected.txt is this program's stdout; omc never produced it. 3 import math 4 # Berggren's tree of primitive triples: every primitive triple appears once, children have larger perimeters 5 M = [((1, -2, 2), (2, -1, 2), (2, -2, 3)), ((1, 2, 2), (2, 1, 2), (2, 2, 3)), ((-1, 2, 2), (-2, 1, 2), (-2, 2, 3))] 6 TOP = 10 ** 7 7 per = [] 8 stack = [(3, 4, 5)] 9 while stack: 10 t = stack.pop() 11 p = sum(t) 12 if p > TOP: 13 continue 14 per.append(p) 15 for m in M: 16 stack.append(tuple(sum(r[i] * t[i] for i in range(3)) for r in m)) 17 for e in range(2, 8): 18 lim = 10 ** e 19 print(f"perimeter <= {lim}: {sum(lim // p for p in per if p <= lim)} triples, {sum(1 for p in per if p <= lim)} primitive")