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/kaprekar-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 / kaprekar-numbers.wiki` 79 lines ยท 1567 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 sp " " 8 text hdr "Kaprekar numbers below 10000:" 9 text cnt "count of Kaprekar numbers below `1000000`: " 10 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 11 fn emit a view uchar * to void 12 o = ulong 0 13 while lt o len a bound 4096 14 k = write 1 a o sub len a o 15 if le k 0 16 exit 1 17 end 18 o = add o ulong k 19 end 20 end 21 note emitu writes n in decimal; 20 digits hold every ulong 22 fn emitu n ulong to void 23 d = new uchar 20 0 24 i = ulong 20 25 v = n 26 while true bound 20 27 i = sub i 1 28 put d i uchar add rem v 10 48 29 v = div v 10 30 if eq v 0 31 break 32 end 33 end 34 emit part d i sub 20 i 35 end 36 note n is Kaprekar when n * n splits as a * 10^k + b with b > 0 and a + b = n (1 counts by definition) 37 note bound: n < 10^6, so n * n < 10^12 and p walks at most 12 powers of ten 38 fn kap n ulong to bool 39 if eq n 1 40 ret true 41 end 42 sq = mul n n 43 p = ulong 10 44 while le p sq bound 20 45 b = rem sq p 46 if gt b 0 47 if eq add div sq p b n 48 ret true 49 end 50 end 51 p = mul p 10 52 end 53 ret false 54 end 55 fn main to int 56 emit hdr 57 c = ulong 0 58 for i ulong 999999 59 n = add i 1 60 if kap n 61 c = add c 1 62 if lt n 10000 63 emit sp 64 emitu n 65 end 66 end 67 end 68 emit nl 69 emit cnt 70 emitu c 71 emit nl 72 ret 0 73 end 74 75 {{out}} 76

77 Kaprekar numbers below 10000: 1 9 45 55 99 297 703 999 2223 2728 4879 4950 5050 5292 7272 7777 9999

78 count of Kaprekar numbers below `1000000`: 54

79