createSudoku.js

    0

    0

    The code will create a fifteen box Sudoku puzzle.

    function sudokuGenerator(paramsNumber) {
    
      let sudoku = []
      let finalArr = []
      let arr = Array(paramsNumber)
        .fill(0)
        .map((arr, index) => index + 1)
    
      for (let i = 0; i < paramsNumber; i++) {
        sudoku[i] = [...arr]
    
        if (sudoku.every((el) => el.length === paramsNumber)) {
          if (sudoku.some((el) => el.some((el, index) => el === index + 1))) {
            while (sudoku.some((el) => el.some((el, index) => el === index + 1))) {
              finalArr = [...sudoku].map((el) => el.sort(() => Math.random() - 0.5))
            }
          }
        }
      }
    
      console.log(finalArr)
    }
    
    sudokuGenerator(9)
    
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.