Count the coins: Difference between revisions

J: be a little clearer, in describing what we are doing
m (→‎{{header|REXX}}: removed a blank line, added verbage to the '''output''' section. -- ~~~~)
(J: be a little clearer, in describing what we are doing)
Line 794:
=={{header|J}}==
 
In this draft intermediate results are a two column array. The first column is tallies and-- the number of ways we have for reaching the total represented in the second column, which is unallocated value (which we will assume are pennies). We will have one row for each different in-range value which can be represented using only nickles (0, 5, 10, ... 95, 100).
 
<lang j>merge=: ({:"1 (+/@:({."1),{:@{:)/. ])@;
count=: {.@] <@,. {:@] - [ * [ i.@>:@<.@%~ {:@]
init=: (1 ,. ,.)^:(0=#@$)
nsplits=: 0 { [: +/@:({."1) [: (merge@:(count"1) init)/ }.@/:~@~.@,</lang>
 
This implementation special cases the handling of pennies and assumes that the lowest coin value in the argument is 1. If I needed additional performance, I would next special case the handling of nickles/penny combinations...
6,962

edits