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/hofstadter-figure-figure-sequences/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 / 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. 3 import itertools 4 5 def 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 15 R = [r for r, _ in itertools.islice(figure_figure(), 40)] 16 S = [s for _, s in itertools.islice(figure_figure(), 960)] 17 print("R(1) to R(10): " + " ".join(map(str, R[:10]))) 18 ok = sorted(R + S) == list(range(1, 1001)) 19 print("first 40 R and first 960 S cover 1..1000 exactly once: " + ("yes" if ok else "no"))