-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenrator.js
86 lines (69 loc) · 2.71 KB
/
genrator.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const fs = require('fs');
num = "15";
for(let num=0;num<=15;num++)
{
// constraints
valueHigh = 10000;
valueLow = -10000;
blocksHigh = 100000;
linesHigh = 1000000;
const char = "qwertyuiopasdfghjklzxcvbnm".split("");
const tasks = [
"CREATE_BLOCK",
"CLOSE_BLOCK",
"ADD_VAR",
"PRINT_VAR",
]
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1) + min); // The maximum is inclusive and the minimum is inclusive
}
// function getRandomVar() {
// return char[getRandomIntInclusive(0, char.length - 1)];
// }
function getRandomValue() {
return getRandomIntInclusive(valueLow, valueHigh);
}
function getRandomTask() {
return tasks[getRandomIntInclusive(0, tasks.length - 1)];
}
let openBlocks = 0;
let totalBlocks = 0;
let test_case = [];
let count = 0;
// while(totalBlocks < blocksHigh && test_case.length < linesHigh - openBlocks) {
// count++;
// if(count % 100000 == 0) console.log("Run: ", count++);
// const task = getRandomTask();
// switch (task) {
// case "CREATE_BLOCK":
// if(totalBlocks < blocksHigh && test_case.length < linesHigh - openBlocks - 1) {
// test_case.push("{");
// openBlocks++
// totalBlocks++;
// }
// break;
// case "CLOSE_BLOCK":
// if(openBlocks > 0) {
// test_case.push("}");
// openBlocks--;
// }
// break;
// case "ADD_VAR":
// test_case.push(getRandomVar() + " = " + getRandomValue());
// break;
// case "PRINT_VAR":
// test_case.push("print " + getRandomVar());
// break;
// }
// }
// while (openBlocks > 0) {
// test_case.push("}");
// openBlocks--;
// }
test_case.push(getRandomValue() + " " + getRandomValue());
// test_case = [test_case.length, ...test_case];
fs.writeFileSync(`./input${num}.txt`, test_case.join("\n"));
console.assert(openBlocks == 0);
}