Created
May 17, 2016 13:40
-
-
Save Daymannovaes/d1f57bc80d16e58bb0b5c9180ea1b3b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var output = ""; | |
/** | |
* EXPLAINING | |
* | |
* The 'output' var holds the string with the generated output, | |
* which should be used as INPUT in the PA | |
* | |
* HOW TO USE | |
* | |
* > copy all this code (yes, all of it) | |
* > open the console browser (hit f12 in your browser, then go to console tab) | |
* > this console runs javascript, paste all this code there and hit enter. | |
* > call the function genN, passing the number of test cases you want. | |
* > the output will be in the 'output' var | |
* | |
* EXAMPLE | |
* | |
* genN(5); // 5 test cases | |
*/ | |
function genN(_n) { | |
output = _n + "\n"; | |
var i; | |
var n, v, max; | |
for(i=0; i<_n; i++) { | |
n = rand(1, 25); | |
max = parseInt((n*n)/2); | |
v = rand(0, max); | |
gen(n, v); | |
} | |
return output; | |
} | |
function gen(n, v) { | |
output += n + " " + v + "\n"; | |
var i; | |
var random; | |
for(i=0; i<v; i++) { | |
random = rand(1, n); | |
output += random + " "; | |
random = rand(1, n); | |
output += random + "\n"; | |
} | |
} | |
function rand(min, max) { | |
var n; | |
n = Math.random() * (max * 1000); | |
n = Math.floor(n); | |
n = (n%max) + min; | |
return n; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment