Skip to content

Commit

Permalink
Add proof solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Cool-Katt committed Oct 23, 2024
1 parent be4828b commit 3577383
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions exercises/practice/killer-sudoku-helper/.meta/proof.ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export const combinations = (cage) => {
const { sum, size, exclude } = cage;
const result = [];
const digits = [...Array(10).keys()]
.slice(1)
.filter((d) => !exclude.includes(d));

function findCombinations(remainingSum, index, combination) {
if (remainingSum === 0 && combination.length === size) {
result.push(combination);
return;
}

for (let i = index; i < digits.length; i++) {
const digit = digits[i];
if (digit > remainingSum) {
break;
}
if (combination.includes(digit)) {
continue;
}
findCombinations(remainingSum - digit, i + 1, [...combination, digit]);
}
}

findCombinations(sum, 0, []);
return result;
};

0 comments on commit 3577383

Please sign in to comment.