Skip to content

DP algorithm for min-coin-change.js  #200

@aldendmw

Description

@aldendmw

I guess there is a minor error, in the dynamic programming for min coin change in chapter 14, in the function makeChange there is a for block:

    for (let i = 0; i < coins.length; i++) {
      const coin = coins[i];
      newAmount = value - coin;
      if (newAmount >= 0) {
        newMin = makeChange(newAmount);
      }
      if (
        newAmount >= 0
        && (newMin.length < min.length - 1 || !min.length)
        && (newMin.length || !newAmount)
      ) {
        min = [coin].concat(newMin);
        // console.log('new Min ' + min + ' for ' + amount);
      }
    }

where in the commented line
console.log('new Min ' + min + ' for ' + amount);
I suppose it is for printing each cycle of the algorithm according to the published book, however
it should not be 'amount' or 'newAmount' I think, instead,
console.log('new Min ' + min + ' for ' + value);
will be in line with the out print for each loop

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy