interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

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.
3from 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), ...
6a = [0, 1]
7for n in range(2, 1201):
8 a.append(a[n // 2] if n % 2 == 0 else a[n // 2] + a[n // 2 + 1])
9s = a[1:]
10print("first 15:", *s[:15])
11for v in list(range(1, 11)) + [100]:
12 print(f"{v} first appears at {s.index(v) + 1}")
13print("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")