-
Notifications
You must be signed in to change notification settings - Fork 0
/
drStrange.js
38 lines (34 loc) · 949 Bytes
/
drStrange.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function subsequence(ans, arr, low, high) {
if (low <= high + 1 && ans.length != 0)
console.log(ans);
for (let i = low; i <= high; i++)
subsequence(ans + arr[i] + " ", arr, i + 1, high);
}
function runProgram(input) {
let n = Number(input);
let arr = [];
for (let i = 1; i <= n; i++)
arr.push(i + "");
console.log(" ");
subsequence("", arr, 0, arr.length - 1);
}
if (process.env.USERNAME === "Ajit") {
runProgram(`3`);
} else {
process.stdin.resume();
process.stdin.setEncoding("ascii");
let read = "";
process.stdin.on("data", function (input) {
read += input;
});
process.stdin.on("end", function () {
read = read.replace(/\n$/, "");
read = read.replace(/\n$/, "");
runProgram(read);
});
process.on("SIGINT", function () {
read = read.replace(/\n$/, "");
runProgram(read);
process.exit(0);
});
}