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/stern-brocot-sequence/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 / stern-brocot-sequence / oracle.py` 13 lines ยท 682 bytes Raw Blame History 1 # Independent reference for "Stern-Brocot sequence" (Python 3, standard library only). 2 # expected.txt is this program's stdout; omc never produced it. 3 from math import gcd 4 # Stern's diatomic recurrence: a(1) = 1, a(2n) = a(n), a(2n+1) = a(n) + a(n+1); the Stern-Brocot 5 # sequence of the task is a(1), a(2), ... 6 a = [0, 1] 7 for n in range(2, 1201): 8 a.append(a[n // 2] if n % 2 == 0 else a[n // 2] + a[n // 2 + 1]) 9 s = a[1:] 10 print("first 15:", *s[:15]) 11 for v in list(range(1, 11)) + [100]: 12 print(f"{v} first appears at {s.index(v) + 1}") 13 print("gcd of each consecutive pair of the first 1000 is 1:", "yes" if all(gcd(x, y) == 1 for x, y in zip(s[:1000], s[1:1000])) else "no")