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/sum-digits-of-an-integer/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 / sum-digits-of-an-integer / oracle.py` 14 lines ยท 559 bytes Raw Blame History 1 # Independent reference for "Sum digits of an integer" (Python 3, standard library only). 2 # expected.txt is this program's stdout; omc never produced it. 3 import string 4 DIG = string.digits + string.ascii_lowercase 5 def digits(n, b): 6 out = [] 7 while True: 8 n, r = divmod(n, b) 9 out.append(r) 10 if n == 0: 11 return out[::-1] 12 for n, b in [(1, 10), (1234, 10), (0xfe, 16), (0xf0e, 16), (255, 8), (2**64 - 1, 2), (2**64 - 1, 36)]: 13 ds = digits(n, b) 14 print(f"{''.join(DIG[d] for d in ds)} (base {b}): digit sum {sum(ds)}")