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/sum-multiples-of-3-and-5.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 / sum-multiples-of-3-and-5.wiki` 76 lines ยท 1729 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 loop "by loop, below 1000: " 8 text pre "by formula, below 10^" 9 text col ": " 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 the multiples of k below n add up to k * m * (m + 1) / 2 with m = (n - 1) / k; inclusion-exclusion 37 note removes the multiples of 15 counted twice. Below 10^9 every product stays under 2^64 38 fn sm k ulong n ulong to ulong 39 m = div sub n 1 k 40 ret div mul mul k m add m 1 2 41 end 42 fn main to int 43 s = ulong 0 44 for i ulong 1000 45 if or eq rem i 3 0 eq rem i 5 0 46 s = add s i 47 end 48 end 49 emit loop 50 emitu s 51 emit nl 52 n = ulong 10 53 for e ulong 9 54 emit pre 55 emitu add e 1 56 emit col 57 emitu sub add sm 3 n sm 5 n sm 15 n 58 emit nl 59 n = mul n 10 60 end 61 ret 0 62 end 63 64 {{out}} 65

66 by loop, below 1000: 233168

67 by formula, below 10^1: 23

68 by formula, below 10^2: 2318

69 by formula, below 10^3: 233168

70 by formula, below 10^4: `23331668`

71 by formula, below 10^5: `2333316668`

72 by formula, below 10^6: `233333166668`

73 by formula, below 10^7: `23333331666668`

74 by formula, below 10^8: `2333333316666668`

75 by formula, below 10^9: `233333333166666668`

76