Skip to content

Instantly share code, notes, and snippets.

@webercoder
Created March 2, 2019 01:01
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 webercoder/43f7530ec67f375a1fe86da06ec257cd to your computer and use it in GitHub Desktop.
Save webercoder/43f7530ec67f375a1fe86da06ec257cd to your computer and use it in GitHub Desktop.
make-number-puzzle.js
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
function makePuzzle(rows = 5, columns = 5, max = 20) {
const find = getRandomInt(max);
console.log(`Find the number ${find}`);
const puzzle = [];
for (let i = 0; i < rows; i++) {
puzzle[i] = [];
const findColumn = getRandomInt(columns);
for (let j = 0; j < columns; j++) {
if (j === findColumn - 1) {
puzzle[i].push(find);
} else {
puzzle[i].push(getRandomInt(max));
}
}
}
puzzle.forEach(row => console.log(row.join('\t')));
console.log(' ');
}
for (let i = 0; i < 7; i++) {
makePuzzle();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment