interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / hofstadter-figure-figure-sequences / oracle.py

19 lines · 764 bytes Raw Blame History
1# Independent reference for "Hofstadter Figure-Figure sequences" (Python 3, standard library only).
2# expected.txt is this program's stdout; omc never produced it.
3import itertools
4
5def figure_figure():
6 # R(n) = R(n-1) + S(n-1); S runs through the positive integers that R skips
7 r, rs, s = 1, {1}, 2
8 yield r, s
9 while True:
10 r += s
11 rs.add(r)
12 s = next(c for c in itertools.count(s + 1) if c not in rs)
13 yield r, s
14
15R = [r for r, _ in itertools.islice(figure_figure(), 40)]
16S = [s for _, s in itertools.islice(figure_figure(), 960)]
17print("R(1) to R(10): " + " ".join(map(str, R[:10])))
18ok = sorted(R + S) == list(range(1, 1001))
19print("first 40 R and first 960 S cover 1..1000 exactly once: " + ("yes" if ok else "no"))