For completeness, the solution I ended up using was to pop! a coin from the list, then call the method recursively *twice* - once for the case when the coin is used (and the recursive total is thus reduced by the coin’s value) and one where it’s not (and the total stays the same). Before returning, I push! the item back on the list.
// T On Monday, December 21, 2015 at 9:33:17 PM UTC+1, Tomas Lycken wrote: The algorithm I want to implement is fairly simple - it's a basic change > making problem: "given the following coins [20 coins with integer-values > between 1 and 50] how many ways is there to combine them to get a total > value of 150? two coins with equal value contribute one time each to a > combination involving only one of them." > > My approach was based on this SO answer > <http://stackoverflow.com/a/14993011/38055>, basically figuring it out > based on how many ways there are to get a total value of 150-x from the > list of all coins except x. I might be able to remove and re-insert the > value, but ordering is important (since I'll loop over the values, and I > only want to test each value once on each level). > > I'll have to think about this some more, but at least now I know that my > naïve approach is impossible to optimize regardless of my inability to > construct the indexing array efficiently :) > > Thanks! > > // T > > On Monday, December 21, 2015 at 6:57:39 PM UTC+1, Tero Frondelius wrote: >> >> Hi >> Can you use a macro to produce your twenty nested loops? > >