OurBigBook logoOurBigBook Docs OurBigBook logoOurBigBook.comSite Source code
generate-deep-tree
#!/usr/bin/env node

// https://docs.ourbigbook.com#autogenerated-tests

const cli_args = process.argv.slice(2);

let spread;
if (cli_args.length > 0) {
  spread = parseInt(cli_args[0]);
} else {
  spread = 2;
}

let depth;
if (cli_args.length > 1) {
  depth = parseInt(cli_args[1]);
} else {
  depth = 5;
}

console.log('= 0\n');
const levels = [1];
while (levels.length > 0) {
  console.log('='.repeat(levels.length + 1) + ' ' + levels.join(' ') + '\n');
  if (levels.length < depth) {
    levels.push(1);
  } else {
    while (levels[levels.length - 1] === spread) {
      levels.pop();
    }
    levels[levels.length - 1] = levels[levels.length - 1] + 1;
  }
}