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-q-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 / hofstadter-q-sequence / oracle.py` 12 lines ยท 598 bytes Raw Blame History 1 # Independent reference for "Hofstadter Q sequence" (Python 3, standard library only). 2 # expected.txt is this program's stdout; omc never produced it. 3 q = {1: 1, 2: 1} 4 def Q(n): 5 # fill Q(len(q)+1) .. Q(n) in order; each term uses only earlier ones 6 for m in range(len(q) + 1, n + 1): 7 q[m] = q[m - q[m - 1]] + q[m - q[m - 2]] 8 return q[n] 9 Q(100000) 10 print("first 10 terms: " + " ".join(str(Q(n)) for n in range(1, 11))) 11 print(f"the 1000th term: {Q(1000)}") 12 print(f"terms up to the 100000th that are less than the term before: {sum(1 for n in range(2, 100001) if q[n] < q[n - 1])}")