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/harshad-or-niven-series.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 / harshad-or-niven-series.wiki` 74 lines ยท 1509 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 first "first 20 Harshad numbers:" 9 text above "first Harshad number above 1000: " 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 a Harshad number when its digit sum divides it 37 fn harshad n ulong to bool 38 s = ulong 0 39 v = n 40 while gt v 0 bound 20 41 s = add s rem v 10 42 v = div v 10 43 end 44 ret eq rem n s 0 45 end 46 note bound: every multiple of 10 up to 100 is Harshad, so neither search passes 1000 candidates 47 fn main to int 48 emit first 49 n = ulong 0 50 k = ulong 0 51 while lt k 20 bound 1000 52 n = add n 1 53 if harshad n 54 emit sp 55 emitu n 56 k = add k 1 57 end 58 end 59 emit nl 60 n = ulong 1001 61 while not harshad n bound 1000 62 n = add n 1 63 end 64 emit above 65 emitu n 66 emit nl 67 ret 0 68 end 69 70 {{out}} 71

72 first 20 Harshad numbers: 1 2 3 4 5 6 7 8 9 10 12 18 20 21 24 27 30 36 40 42

73 first Harshad number above 1000: 1002

74