Skip to content

Instantly share code, notes, and snippets.

@Daymannovaes
Last active April 26, 2016 11:57
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/fa9aaf60e49ceaba423348f573bf218f to your computer and use it in GitHub Desktop.
Save Daymannovaes/fa9aaf60e49ceaba423348f573bf218f to your computer and use it in GitHub Desktop.
var output = "";
var rateCovered = 0.2;
/**
* EXPLAINING
*
* The 'output' var holds the string with the generated output,
* which should be used as INPUT in the PA
*
* the 'rateCovered' var holds the chance of a square not be a tip.
*
* 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
* output; // or console.log(output);
*/
function genN(_n) {
var i;
var n, m, k;
for(i=0; i<_n; i++) {
n = rand(1, 25); // should have max of 25
m = rand(1, 20);
k = rand(1, n*m < 30 ? n*m : 30);
gen(n, m, k);
}
output += "0 0 0\n";
}
function gen(n, m, k) {
output += n + " " + m + " " + k + "\n";
var i, j;
var random;
for(i=0; i<n; i++) {
for(j=0; j<m; j++) {
random = Math.random();
if(random < rateCovered) output += ".";
else output += rand(1, 8);
}
output += "\n";
}
for(i=0; i<k; i++) {
random = (Math.floor(Math.random() * 1000)%n) + 1;
output += random + " ";
random = (Math.floor(Math.random() * 1000)%m) + 1;
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