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/additive-primes.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 / additive-primes.wiki`
106 lines ยท 1920 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 hdr "additive primes below 500 (prime, and the digit sum is prime):\n"
8 text cnt "count: "
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 emitw writes n in decimal right-aligned in w columns (w at most 20)
36 fn emitw n ulong w ulong to void
37 d = new uchar 20 32
38 i = ulong 20
39 v = n
40 while true bound 20
41 i = sub i 1
42 put d i uchar add rem v 10 48
43 v = div v 10
44 if eq v 0
45 break
46 end
47 end
48 if gt i sub 20 w
49 i = sub 20 w
50 end
51 emit part d i sub 20 i
52 end
53 fn isprime n ulong to bool
54 if lt n 2
55 ret false
56 end
57 d = ulong 2
58 while le mul d d n bound 32
59 if eq rem n d 0
60 ret false
61 end
62 d = add d 1
63 end
64 ret true
65 end
66 fn dsum n ulong to ulong
67 s = ulong 0
68 v = n
69 while gt v 0 bound 4
70 s = add s rem v 10
71 v = div v 10
72 end
73 ret s
74 end
75 fn main to int
76 emit hdr
77 c = ulong 0
78 for n ulong 500
79 if isprime n
80 if isprime dsum n
81 emitw n 4
82 c = add c 1
83 if eq rem c 10 0
84 emit nl
85 end
86 end
87 end
88 end
89 emit nl
90 emit cnt
91 emitu c
92 emit nl
93 ret 0
94 end
95
96 {{out}}
97
98 additive primes below 500 (prime, and the digit sum is prime):
99 2 3 5 7 11 23 29 41 43 47
100 61 67 83 89 101 113 131 137 139 151
101 157 173 179 191 193 197 199 223 227 229
102 241 263 269 281 283 311 313 317 331 337
103 353 359 373 379 397 401 409 421 443 449
104 461 463 467 487
105 count: 54
106