notchCombos = {
let queue = Immutable.List();
queue = queue.push({ chosen: Immutable.List(), notchesUsed: 0, cursor: 0 });
let options = Immutable.List();
const charmsWithCost = charms.filter((c) => c.notchCost > 0);
while (queue.size > 0) {
const inProgress = queue.first();
queue = queue.shift();
const consideredCharm = charmsWithCost[inProgress.cursor];
if (consideredCharm) {
const nextChosen = inProgress.chosen.push(consideredCharm);
if (inProgress.notchesUsed + consideredCharm.notchCost <= maxNotches) {
options = options.push(nextChosen);
queue = queue.push({
chosen: nextChosen,
notchesUsed: inProgress.notchesUsed + consideredCharm.notchCost,
cursor: inProgress.cursor + 1
});
}
queue = queue.push({
chosen: inProgress.chosen,
notchesUsed: inProgress.notchesUsed,
cursor: inProgress.cursor + 1
});
}
}
return options.toJS().map((charms) => ({
charms,
totalNotchCost: charms.reduce((s, c) => s + c.notchCost, 0)
}));
}