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/almost-prime/almost-prime.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 / almost-prime / almost-prime.om` 72 lines ยท 1225 bytes Raw Blame History 1 note Rosetta Code task "Almost prime": https://rosettacode.org/wiki/Almost_prime 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text sp " " 6 text kk "k = " 7 text col ":" 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 a k-almost prime has exactly k prime factors counted with multiplicity 35 fn bigo n ulong to ulong 36 v = n 37 d = ulong 2 38 k = ulong 0 39 while le mul d d v bound 64 40 if eq rem v d 0 41 k = add k 1 42 v = div v d 43 else 44 d = add d 1 45 end 46 end 47 if gt v 1 48 k = add k 1 49 end 50 ret k 51 end 52 note bound: the 10th 5-almost prime is 176, so no list needs more than 200 candidates 53 fn main to int 54 for j ulong 5 55 k = add j 1 56 emit kk 57 emitu k 58 emit col 59 c = ulong 0 60 n = ulong 2 61 while lt c 10 bound 200 62 if eq bigo n k 63 emit sp 64 emitu n 65 c = add c 1 66 end 67 n = add n 1 68 end 69 emit nl 70 end 71 ret 0 72 end