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/additive-primes/additive-primes.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 / additive-primes / additive-primes.om` 92 lines ยท 1495 bytes Raw Blame History 1 note Rosetta Code task "Additive primes": https://rosettacode.org/wiki/Additive_primes 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text hdr "additive primes below 500 (prime, and the digit sum is prime):\n" 6 text cnt "count: " 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 emitw writes n in decimal right-aligned in w columns (w at most 20) 34 fn emitw n ulong w ulong to void 35 d = new uchar 20 32 36 i = ulong 20 37 v = n 38 while true bound 20 39 i = sub i 1 40 put d i uchar add rem v 10 48 41 v = div v 10 42 if eq v 0 43 break 44 end 45 end 46 if gt i sub 20 w 47 i = sub 20 w 48 end 49 emit part d i sub 20 i 50 end 51 fn isprime n ulong to bool 52 if lt n 2 53 ret false 54 end 55 d = ulong 2 56 while le mul d d n bound 32 57 if eq rem n d 0 58 ret false 59 end 60 d = add d 1 61 end 62 ret true 63 end 64 fn dsum n ulong to ulong 65 s = ulong 0 66 v = n 67 while gt v 0 bound 4 68 s = add s rem v 10 69 v = div v 10 70 end 71 ret s 72 end 73 fn main to int 74 emit hdr 75 c = ulong 0 76 for n ulong 500 77 if isprime n 78 if isprime dsum n 79 emitw n 4 80 c = add c 1 81 if eq rem c 10 0 82 emit nl 83 end 84 end 85 end 86 end 87 emit nl 88 emit cnt 89 emitu c 90 emit nl 91 ret 0 92 end