Skip to content

Instantly share code, notes, and snippets.

@Daymannovaes
Last active May 13, 2016 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daymannovaes/6008e456ea54409867c0065876670017 to your computer and use it in GitHub Desktop.
Save Daymannovaes/6008e456ea54409867c0065876670017 to your computer and use it in GitHub Desktop.
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 = "";
var i;
var c, p, max;
for(i=0; i<_n; i++) {
c = rand(1, 25);
max = (c*c + c - 2)/2;
p = rand(1, max > 20 ? max : 20);
gen(c, p);
}
return output;
}
function gen(c, p) {
output += c + " " + p + "\n";
var i;
var random;
for(i=0; i<p; i++) {
random = rand(1, c);
output += random + " ";
random = rand(1, c);
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