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/attractive-numbers/attractive-numbers.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 / attractive-numbers / attractive-numbers.om` 85 lines ยท 1568 bytes Raw Blame History 1 note Rosetta Code task "Attractive numbers": https://rosettacode.org/wiki/Attractive_numbers 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text hdr "attractive numbers up to 120 (the count of prime factors, with multiplicity, is prime):\n" 6 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 7 fn emit a view uchar * to void 8 o = ulong 0 9 while lt o len a bound 4096 10 k = write 1 a o sub len a o 11 if le k 0 12 exit 1 13 end 14 o = add o ulong k 15 end 16 end 17 note emitu writes n in decimal; 20 digits hold every ulong 18 fn emitu n ulong to void 19 d = new uchar 20 0 20 i = ulong 20 21 v = n 22 while true bound 20 23 i = sub i 1 24 put d i uchar add rem v 10 48 25 v = div v 10 26 if eq v 0 27 break 28 end 29 end 30 emit part d i sub 20 i 31 end 32 note emitw writes n in decimal right-aligned in w columns (w at most 20) 33 fn emitw n ulong w ulong to void 34 d = new uchar 20 32 35 i = ulong 20 36 v = n 37 while true bound 20 38 i = sub i 1 39 put d i uchar add rem v 10 48 40 v = div v 10 41 if eq v 0 42 break 43 end 44 end 45 if gt i sub 20 w 46 i = sub 20 w 47 end 48 emit part d i sub 20 i 49 end 50 note Omega(n): the number of prime factors of n counted with multiplicity 51 fn bigo n ulong to ulong 52 v = n 53 d = ulong 2 54 k = ulong 0 55 while le mul d d v bound 64 56 if eq rem v d 0 57 k = add k 1 58 v = div v d 59 else 60 d = add d 1 61 end 62 end 63 if gt v 1 64 k = add k 1 65 end 66 ret k 67 end 68 note Omega(n) <= 6 for n <= 120, so the primes to test are 2, 3 and 5 69 fn main to int 70 emit hdr 71 c = ulong 0 72 for i ulong 120 73 n = add i 1 74 k = bigo n 75 if or or eq k 2 eq k 3 eq k 5 76 emitw n 4 77 c = add c 1 78 if eq rem c 20 0 79 emit nl 80 end 81 end 82 end 83 emit nl 84 ret 0 85 end