Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var numbersAmount = 5;
- console.log("Please enter the amount of the numbers 1...N, N = " + numbersAmount);
- var combinationsAmount = 3;
- console.log("Please enter the amount of the combinations K = " + combinationsAmount);
- var vector = new Array(combinationsAmount);
- debugger;
- combinations(combinationsAmount - 1, vector, numbersAmount, 1);
- function combinations(index, vector, numbersLength, start) {
- if (index == -1) {
- console.log(vector);
- }
- else {
- for (let i = start; i <= numbersLength; i++) {
- vector[index] = i;
- combinations(index - 1, vector, (numbersLength), (i + 1));
- }
- }
- }
- var arr = "abcde";
- var numbersAmount = arr.length;
- console.log("Please enter the amount of the numbers 1...N, N = " + numbersAmount);
- var combinationsAmount = 3;
- console.log("Please enter the amount of the combinations K = " + combinationsAmount);
- var vector = new Array(combinationsAmount);
- debugger;
- combinations(combinationsAmount - 1, vector, numbersAmount, 1);
- function combinations(index, vector, numbersLength, start) {
- if (index == -1) {
- console.log(vector);
- }
- else {
- for (let i = start; i <= numbersLength; i++) {
- vector[index] = arr[i-1];
- combinations(index - 1, vector, (numbersLength), (i + 1));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement