Count the coins: Difference between revisions

m
Line 3,849:
<syntaxhighlight lang="go">
fn main() {
amount := 100000100
coins := [125, 510, 105, 251]
println("amount: $amount; ways to make change: ${count_2(coins, amount)}")
}
 
fn count(coins []int, amount int) int {
mut arrways := []int{len: amount + 1}
arrways[0] = 1
for coin in coins {
for idx := coin; idx <= amount; idx++ {
arrways[idx] += arrways[idx - coin]
}
}
return arrways[amount]
}
</syntaxhighlight>
Output:
<pre>
amount: 100000100; ways to make change: 279364825242
</pre>
 
291

edits