fix: target without divisor denoms is no shortcut condition
This commit is contained in:
parent
f846f7e8cc
commit
8abbc792f6
1 changed files with 1 additions and 6 deletions
|
|
@ -24,11 +24,6 @@ const prepare_denominations = denominations =>
|
||||||
const max_denomination_multiplicity = (denom, count, target) =>
|
const max_denomination_multiplicity = (denom, count, target) =>
|
||||||
Math.min(count, Math.floor(target / denom))
|
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;
|
* @returns null if there's no solution set;
|
||||||
* false if there's no solution;
|
* 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
|
* of the denominations, or if the target is not divisible by any of the
|
||||||
* denominations
|
* denominations
|
||||||
*/
|
*/
|
||||||
if (target > csum || !has_divisor(didx, denominations, target))
|
if (target > csum)
|
||||||
return memo_set(memo, target, denom, false)
|
return memo_set(memo, target, denom, false)
|
||||||
|
|
||||||
let solution = memo_get(memo, target, denom)
|
let solution = memo_get(memo, target, denom)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue