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/semiprime.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 / semiprime.wiki`
93 lines ยท 1655 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 sp " "
8 text lst "semiprimes below 100:"
9 text cnt "semiprimes below 10000: "
10 text tst "1679 = 23 * 73 is semiprime: "
11 text yes "yes\n"
12 text no "no\n"
13 note emit writes every byte of a to stdout; a short write is retried, an error exits 1
14 fn emit a view uchar * to void
15 o = ulong 0
16 while lt o len a bound 4096
17 k = write 1 a o sub len a o
18 if le k 0
19 exit 1
20 end
21 o = add o ulong k
22 end
23 end
24 note emitu writes n in decimal; 20 digits hold every ulong
25 fn emitu n ulong to void
26 d = new uchar 20 0
27 i = ulong 20
28 v = n
29 while true bound 20
30 i = sub i 1
31 put d i uchar add rem v 10 48
32 v = div v 10
33 if eq v 0
34 break
35 end
36 end
37 emit part d i sub 20 i
38 end
39 note semiprime: the least factor d of n leaves a prime cofactor n / d
40 fn semi n ulong to bool
41 if lt n 4
42 ret false
43 end
44 d = ulong 2
45 while le mul d d n bound 100
46 if eq rem n d 0
47 m = div n d
48 e = ulong 2
49 while le mul e e m bound 100
50 if eq rem m e 0
51 ret false
52 end
53 e = add e 1
54 end
55 ret true
56 end
57 d = add d 1
58 end
59 ret false
60 end
61 fn main to int
62 emit lst
63 for n ulong 100
64 if semi n
65 emit sp
66 emitu n
67 end
68 end
69 emit nl
70 c = ulong 0
71 for n ulong 10000
72 if semi n
73 c = add c 1
74 end
75 end
76 emit cnt
77 emitu c
78 emit nl
79 emit tst
80 if semi 1679
81 emit yes
82 else
83 emit no
84 end
85 ret 0
86 end
87
88 {{out}}
89
90 semiprimes below 100: 4 6 9 10 14 15 21 22 25 26 33 34 35 38 39 46 49 51 55 57 58 62 65 69 74 77 82 85 86 87 91 93 94 95
91 semiprimes below 10000: 2625
92 1679 = 23 * 73 is semiprime: yes
93