fix: use the same solution format for subset-sum as for coin-change
This commit is contained in:
parent
91c4ca4dce
commit
9ef9a70c39
1 changed files with 2 additions and 8 deletions
|
|
@ -116,14 +116,8 @@ const getSolution_old = (units, amount, mode) => {
|
||||||
|
|
||||||
const solver = sumService.subsetSum(billList, amount.toNumber())
|
const solver = sumService.subsetSum(billList, amount.toNumber())
|
||||||
const solution = _.countBy(Math.floor, solver.next().value)
|
const solution = _.countBy(Math.floor, solver.next().value)
|
||||||
return _.reduce(
|
return Object.entries(solution)
|
||||||
(acc, value) => {
|
.map(([denomination, provisioned]) => [_.toNumber(denomination), provisioned])
|
||||||
acc.push({ denomination: _.toNumber(value), provisioned: solution[value] })
|
|
||||||
return acc
|
|
||||||
},
|
|
||||||
[],
|
|
||||||
_.keys(solution)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getSolution = (units, amount) => {
|
const getSolution = (units, amount) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue