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/attractive-numbers.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 / attractive-numbers.wiki` 96 lines ยท 2080 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 hdr "attractive numbers up to 120 (the count of prime factors, with multiplicity, is prime):\n" 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 emitw writes n in decimal right-aligned in w columns (w at most 20) 35 fn emitw n ulong w ulong to void 36 d = new uchar 20 32 37 i = ulong 20 38 v = n 39 while true bound 20 40 i = sub i 1 41 put d i uchar add rem v 10 48 42 v = div v 10 43 if eq v 0 44 break 45 end 46 end 47 if gt i sub 20 w 48 i = sub 20 w 49 end 50 emit part d i sub 20 i 51 end 52 note Omega(n): the number of prime factors of n counted with multiplicity 53 fn bigo n ulong to ulong 54 v = n 55 d = ulong 2 56 k = ulong 0 57 while le mul d d v bound 64 58 if eq rem v d 0 59 k = add k 1 60 v = div v d 61 else 62 d = add d 1 63 end 64 end 65 if gt v 1 66 k = add k 1 67 end 68 ret k 69 end 70 note Omega(n) <= 6 for n <= 120, so the primes to test are 2, 3 and 5 71 fn main to int 72 emit hdr 73 c = ulong 0 74 for i ulong 120 75 n = add i 1 76 k = bigo n 77 if or or eq k 2 eq k 3 eq k 5 78 emitw n 4 79 c = add c 1 80 if eq rem c 20 0 81 emit nl 82 end 83 end 84 end 85 emit nl 86 ret 0 87 end 88 89 {{out}} 90

91 attractive numbers up to 120 (the count of prime factors, with multiplicity, is prime):

92 4 6 8 9 10 12 14 15 18 20 21 22 25 26 27 28 30 32 33 34

93 35 38 39 42 44 45 46 48 49 50 51 52 55 57 58 62 63 65 66 68

94 69 70 72 74 75 76 77 78 80 82 85 86 87 91 92 93 94 95 98 99

95 102 105 106 108 110 111 112 114 115 116 117 118 119 120

96