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/roman-numerals-encode/roman-numerals-encode.om # 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 / roman-numerals-encode / roman-numerals-encode.om` 76 lines ยท 1395 bytes Raw Blame History 1 note Rosetta Code task "Roman numerals/Encode": https://rosettacode.org/wiki/Roman_numerals/Encode 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text eqs " = " 6 note symbols packed: even k is one letter, odd k two (M CM D CD C XC L XL X IX V IV I) 7 text sym "MCMDCDCXCLXLXIXVIVI" 8 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 9 fn emit a view uchar * to void 10 o = ulong 0 11 while lt o len a bound 4096 12 k = write 1 a o sub len a o 13 if le k 0 14 exit 1 15 end 16 o = add o ulong k 17 end 18 end 19 note emitu writes n in decimal; 20 digits hold every ulong 20 fn emitu n ulong to void 21 d = new uchar 20 0 22 i = ulong 20 23 v = n 24 while true bound 20 25 i = sub i 1 26 put d i uchar add rem v 10 48 27 v = div v 10 28 if eq v 0 29 break 30 end 31 end 32 emit part d i sub 20 i 33 end 34 note 1 .. 3999; no symbol repeats more than 3 times there, so a larger n traps 4 35 fn roman n ulong to void 36 vals = new ulong 13 0 37 put vals 0 1000 38 put vals 1 900 39 put vals 2 500 40 put vals 3 400 41 put vals 4 100 42 put vals 5 90 43 put vals 6 50 44 put vals 7 40 45 put vals 8 10 46 put vals 9 9 47 put vals 10 5 48 put vals 11 4 49 put vals 12 1 50 emitu n 51 emit eqs 52 v = n 53 for k ulong 13 54 p = mul div k 2 3 55 w = ulong 1 56 if eq rem k 2 1 57 p = add p 1 58 w = 2 59 end 60 while ge v get vals k bound 3 61 emit part sym p w 62 v = sub v get vals k 63 end 64 end 65 emit nl 66 end 67 fn main to int 68 roman 1990 69 roman 2008 70 roman 1666 71 roman 3999 72 roman 4 73 roman 14 74 roman 1 75 ret 0 76 end