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/prime-decomposition/prime-decomposition.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 / prime-decomposition / prime-decomposition.om` 69 lines ยท 1174 bytes Raw Blame History 1 note Rosetta Code task "Prime decomposition": https://rosettacode.org/wiki/Prime_decomposition 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text eqs " = " 6 text times " x " 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 trial division; d stays below 2^32 for these inputs, so mul d d does not wrap 34 fn factor n ulong to void 35 emitu n 36 emit eqs 37 v = n 38 d = ulong 2 39 first = true 40 while le mul d d v bound 999999 41 if eq rem v d 0 42 if not first 43 emit times 44 end 45 first = false 46 emitu d 47 v = div v d 48 else 49 d = add d 1 50 end 51 end 52 if gt v 1 53 if not first 54 emit times 55 end 56 emitu v 57 end 58 emit nl 59 end 60 fn main to int 61 factor 12 62 factor 360 63 factor 97 64 factor 1001 65 factor `2147483647` 66 factor `600851475143` 67 factor `18446744073709551615` 68 ret 0 69 end