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/drafts/rosettacode/digital-root.wiki # 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 / drafts / rosettacode / digital-root.wiki` 82 lines ยท 1748 bytes Raw Blame History 1 =={{header|Omegese}}== 2 {{works with|omc|sha256 `2c824805`, aien-dev/omega-mv `e5b32567`, Linux AArch64}} 3 Omega has no imports, so the small output helpers (emit and friends) are part of the program. 4 5 om2 6 text nl "\n" 7 text per ": additive persistence " 8 text dr ", digital root " 9 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 10 fn emit a view uchar * to void 11 o = ulong 0 12 while lt o len a bound 4096 13 k = write 1 a o sub len a o 14 if le k 0 15 exit 1 16 end 17 o = add o ulong k 18 end 19 end 20 note emitu writes n in decimal; 20 digits hold every ulong 21 fn emitu n ulong to void 22 d = new uchar 20 0 23 i = ulong 20 24 v = n 25 while true bound 20 26 i = sub i 1 27 put d i uchar add rem v 10 48 28 v = div v 10 29 if eq v 0 30 break 31 end 32 end 33 emit part d i sub 20 i 34 end 35 note a ulong has at most 20 digits 36 fn dsum n ulong to ulong 37 s = ulong 0 38 v = n 39 while gt v 0 bound 20 40 s = add s rem v 10 41 v = div v 10 42 end 43 ret s 44 end 45 note bound: one digit sum takes any ulong below 181, the next below 19, then a single digit, so 4 rounds suffice 46 fn tell n ulong to void 47 v = n 48 p = ulong 0 49 while gt v 9 bound 4 50 v = dsum v 51 p = add p 1 52 end 53 emitu n 54 emit per 55 emitu p 56 emit dr 57 emitu v 58 emit nl 59 end 60 fn main to int 61 tell 627615 62 tell 39390 63 tell 588225 64 tell `393900588225` 65 tell 0 66 tell 9 67 tell 199 68 tell `18446744073709551615` 69 ret 0 70 end 71 72 {{out}} 73

74 627615: additive persistence 2, digital root 9

75 39390: additive persistence 2, digital root 6

76 588225: additive persistence 2, digital root 3

77 `393900588225`: additive persistence 2, digital root 9

78 0: additive persistence 0, digital root 0

79 9: additive persistence 0, digital root 9

80 199: additive persistence 3, digital root 1

81 `18446744073709551615`: additive persistence 3, digital root 6

82