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/twin-primes/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 / twin-primes / oracle.py` 14 lines ยท 581 bytes Raw Blame History 1 # Independent reference for "Twin primes" (Python 3, standard library only). 2 # expected.txt is this program's stdout; omc never produced it. 3 import bisect, itertools 4 N = 10**8 5 s = bytearray([1]) * N 6 s[0] = s[1] = 0 7 for i in range(2, 10**4): 8 if s[i]: 9 s[i * i::i] = bytes(len(range(i * i, N, i))) 10 ps = list(itertools.compress(range(N), s)) 11 # the larger member of each twin pair, so "below lim" means that member < lim 12 big = [p + 2 for p in ps if p + 2 < N and s[p + 2]] 13 for e in range(1, 9): 14 print(f"twin prime pairs below {10**e}: {bisect.bisect_left(big, 10**e)}")