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-mv/blob/main/si/rosetta/tasks/digital-root/digital-root.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / si / rosetta / tasks / digital-root / digital-root.om` 68 lines ยท 1230 bytes Raw Blame History 1 note Rosetta Code task "Digital root": https://rosettacode.org/wiki/Digital_root 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text per ": additive persistence " 6 text dr ", digital root " 7 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 8 fn emit a view uchar * to void 9 o = ulong 0 10 while lt o len a bound 4096 11 k = write 1 a o sub len a o 12 if le k 0 13 exit 1 14 end 15 o = add o ulong k 16 end 17 end 18 note emitu writes n in decimal; 20 digits hold every ulong 19 fn emitu n ulong to void 20 d = new uchar 20 0 21 i = ulong 20 22 v = n 23 while true bound 20 24 i = sub i 1 25 put d i uchar add rem v 10 48 26 v = div v 10 27 if eq v 0 28 break 29 end 30 end 31 emit part d i sub 20 i 32 end 33 note a ulong has at most 20 digits 34 fn dsum n ulong to ulong 35 s = ulong 0 36 v = n 37 while gt v 0 bound 20 38 s = add s rem v 10 39 v = div v 10 40 end 41 ret s 42 end 43 note bound: one digit sum takes any ulong below 181, the next below 19, then a single digit, so 4 rounds suffice 44 fn tell n ulong to void 45 v = n 46 p = ulong 0 47 while gt v 9 bound 4 48 v = dsum v 49 p = add p 1 50 end 51 emitu n 52 emit per 53 emitu p 54 emit dr 55 emitu v 56 emit nl 57 end 58 fn main to int 59 tell 627615 60 tell 39390 61 tell 588225 62 tell `393900588225` 63 tell 0 64 tell 9 65 tell 199 66 tell `18446744073709551615` 67 ret 0 68 end