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