Count the coins/0-1: Difference between revisions

no edit summary
No edit summary
Line 126:
Number of ways - order important : 3782932 (all perms of above indices)
</pre>
 
=={{header|Julia}}==
<lang julia>using Combinatorics
 
function coinsum(coins, targetsum; verbose=true)
println("Coins are $coins, target sum is $targetsum:")
combos, perms = 0, 0
for choice in combinations(coins)
if sum(choice) == targetsum
combos += 1
choice = filter(x -> x != 0, choice)
verbose && println("$choice sums to $targetsum")
for perm in permutations(choice)
verbose && println(" permutation: $perm")
perms += 1
end
end
end
println("$combos combinations, $perms permutations.\n")
end
 
coinsum([1, 2, 3, 4, 5], 6)
coinsum([1, 1, 2, 3, 3, 4, 5], 6)
coinsum([1, 2, 3, 4, 5, 5, 5, 5, 15, 15, 10, 10, 10, 10, 25, 100], 40, verbose=false)
</lang>{{out}}
<pre>
Coins are [1, 2, 3, 4, 5], target sum is 6:
[1, 5] sums to 6
permutation: [1, 5]
permutation: [5, 1]
[2, 4] sums to 6
permutation: [2, 4]
permutation: [4, 2]
[1, 2, 3] sums to 6
permutation: [1, 2, 3]
permutation: [1, 3, 2]
permutation: [2, 1, 3]
permutation: [2, 3, 1]
permutation: [3, 1, 2]
permutation: [3, 2, 1]
3 combinations, 10 permutations.
 
Coins are [1, 1, 2, 3, 3, 4, 5], target sum is 6:
[1, 5] sums to 6
permutation: [1, 5]
permutation: [5, 1]
[1, 5] sums to 6
permutation: [1, 5]
permutation: [5, 1]
[2, 4] sums to 6
permutation: [2, 4]
permutation: [4, 2]
[3, 3] sums to 6
permutation: [3, 3]
permutation: [3, 3]
[1, 1, 4] sums to 6
permutation: [1, 1, 4]
permutation: [1, 4, 1]
permutation: [1, 1, 4]
permutation: [1, 4, 1]
permutation: [4, 1, 1]
permutation: [4, 1, 1]
[1, 2, 3] sums to 6
permutation: [1, 2, 3]
permutation: [1, 3, 2]
permutation: [2, 1, 3]
permutation: [2, 3, 1]
permutation: [3, 1, 2]
permutation: [3, 2, 1]
[1, 2, 3] sums to 6
permutation: [1, 2, 3]
permutation: [1, 3, 2]
permutation: [2, 1, 3]
permutation: [2, 3, 1]
permutation: [3, 1, 2]
permutation: [3, 2, 1]
[1, 2, 3] sums to 6
permutation: [1, 2, 3]
permutation: [1, 3, 2]
permutation: [2, 1, 3]
permutation: [2, 3, 1]
permutation: [3, 1, 2]
permutation: [3, 2, 1]
[1, 2, 3] sums to 6
permutation: [1, 2, 3]
permutation: [1, 3, 2]
permutation: [2, 1, 3]
permutation: [2, 3, 1]
permutation: [3, 1, 2]
permutation: [3, 2, 1]
9 combinations, 38 permutations.
 
Coins are [1, 2, 3, 4, 5, 5, 5, 5, 15, 15, 10, 10, 10, 10, 25, 100], target sum is 40:
464 combinations, 3782932 permutations.
</pre>
 
 
=={{header|MiniZinc}}==
4,103

edits