From 8abbc792f613611a7cdb642c42349d83dc89f4ba Mon Sep 17 00:00:00 2001 From: siiky Date: Fri, 31 Jan 2025 13:19:05 +0000 Subject: [PATCH] fix: target without divisor denoms is no shortcut condition --- lib/coin-change.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/coin-change.js b/lib/coin-change.js index 1c9eab5e..4a1c964a 100644 --- a/lib/coin-change.js +++ b/lib/coin-change.js @@ -24,11 +24,6 @@ const prepare_denominations = denominations => const max_denomination_multiplicity = (denom, count, target) => Math.min(count, Math.floor(target / denom)) -const has_divisor = (didx, denominations, target) => - denominations - .slice(didx) - .some(({ denom }) => (target % denom) === 0) - /* * @returns null if there's no solution set; * false if there's no solution; @@ -78,7 +73,7 @@ const solve = (model, target) => { * of the denominations, or if the target is not divisible by any of the * denominations */ - if (target > csum || !has_divisor(didx, denominations, target)) + if (target > csum) return memo_set(memo, target, denom, false) let solution = memo_get(memo, target, denom)