-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblemGenerator.js
More file actions
42 lines (29 loc) · 942 Bytes
/
Copy pathproblemGenerator.js
File metadata and controls
42 lines (29 loc) · 942 Bytes
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
const fs = require('fs');
const code = Math.floor((Math.random() * 100000) + 1);
const NI = 2000; // Number of Items
const WMAX = 2000; // Maximum weight
const problemId = "KSProblem"+code+"-I"+NI+"-WM"+WMAX;
//var problemSize = Math.floor((Math.random() * ((NI*WMAX*2)/3)) + 1);
var problemItems = [];
for(var i = 0; i< NI; i++){
var problemItem = {
item : "item"+i,
value : Math.floor((Math.random() * WMAX) + 1)
};
problemItems.push(problemItem);
}
var totalItemsWeight = problemItems.reduce((totalWeight,item) => {
return totalWeight + item.value;
},0);
var problemSize = totalItemsWeight/2;
var problem = {
id : problemId,
problem : {
items: problemItems,
size : problemSize
}
};
var fileName = "problems/"+problemId+".json";
console.log("Writing problem on "+fileName)+"...";
fs.writeFileSync(fileName, JSON.stringify(problem,null,2));
console.log("Done.");