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/count-the-coins.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 / count-the-coins.wiki` 79 lines ยท 1804 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 minus "-" 9 text t1 "ways to make 100 cents from 1, 5, 10, 25: " 10 text t2 "ways to make 100000 cents from 1, 5, 10, 25, 50, 100: " 11 global ways ulong 100001 12 global coins ulong 6 13 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 14 fn emit a view uchar * to void 15 o = ulong 0 16 while lt o len a bound 4096 17 k = write 1 a o sub len a o 18 if le k 0 19 exit 1 20 end 21 o = add o ulong k 22 end 23 end 24 note emitu writes n in decimal; 20 digits hold every ulong 25 fn emitu n ulong to void 26 d = new uchar 20 0 27 i = ulong 20 28 v = n 29 while true bound 20 30 i = sub i 1 31 put d i uchar add rem v 10 48 32 v = div v 10 33 if eq v 0 34 break 35 end 36 end 37 emit part d i sub 20 i 38 end 39 note addcoin lets every amount from c up to amt also end with a coin c 40 fn addcoin amt ulong c ulong to void 41 for x ulong add sub amt c 1 42 y = add x c 43 w = add get ways y get ways x 44 put ways y w 45 end 46 end 47 note count is the classic change-making dynamic program: ways[a] counts the multisets of the first k 48 note coins that sum to a; adding coin c lets every amount a >= c also end with a c 49 fn count amt ulong k ulong to ulong 50 for a ulong add amt 1 51 put ways a 0 52 end 53 put ways 0 1 54 for i ulong k 55 addcoin amt get coins i 56 end 57 ret get ways amt 58 end 59 fn main to int 60 put coins 0 1 61 put coins 1 5 62 put coins 2 10 63 put coins 3 25 64 put coins 4 50 65 put coins 5 100 66 emit t1 67 emitu count 100 4 68 emit nl 69 emit t2 70 emitu count 100000 6 71 emit nl 72 ret 0 73 end 74 75 {{out}} 76

77 ways to make 100 cents from 1, 5, 10, 25: 242

78 ways to make 100000 cents from 1, 5, 10, 25, 50, 100: `13398445413854501`

79