Count the coins/0-1: Difference between revisions
Content added Content deleted
(J) |
|||
Line 126: | Line 126: | ||
Number of ways - order important : 3782932 (all perms of above indices) |
Number of ways - order important : 3782932 (all perms of above indices) |
||
</pre> |
</pre> |
||
=={{header|J}}== |
|||
Implementation:<lang J>selcoins=: {{ #:I.x=(#:i.2^#y)+/ .*y }} |
|||
ccoins=: {{ (#i), +/!x:+/"1 i=. x selcoins y }}</lang> |
|||
<code>selcoins</code> identifies the valid selections of the coins. <code>ccoins</code> counts then, giving two counts (first is where coin order does not matter, second is where each permutation of physical coins is counted separately). |
|||
Task examples:<lang J> 6 ccoins 1 2 3 4 5 |
|||
3 10 |
|||
6 ccoins 1 1 2 3 3 4 5 |
|||
9 38 |
|||
40 ccoins 1 2 3 4 5 5 5 5 15 15 10 10 10 10 25 100 |
|||
464 3782932</lang> |
|||
=={{header|jq}}== |
=={{header|jq}}== |