npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

sudoku-solver-async

v1.0.10

Published

asynchronous proper sudoku solver which allows you to 'hook' into the function call stack data as the sudoku input puzzle is being solved. useful for writing things like realtime visualisations.

Downloads

7

Readme

Sudoku Solver Asynchronous

a proper sudoku solver where the input has to be 9x9 and with a minimum of 17 clues, uses a brute force recursive backtracking algorithm. the function api has a 2nd optional parameter that allows you to 'hook' into each step in the callstack as the algorithm is executing in 'realtime', this is great for writing visualisations or other apps.

usage

basic usage

// sudoku puzzle input as a 2d array (can also be a 1d array)
const puzzleInput2dArr: number[][] = [
  [9, 1, 5, -1, -1, 3, 4, -1, 6],
  [-1, -1, -1, 1, -1, 2, -1, 8, 9],
  [-1, 6, -1, -1, -1, 4, 7, -1, 3],

  [-1, -1, -1, 3, 1, -1, -1, 9, -1],
  [5, -1, 8, -1, 4, -1, -1, 3, 2],
  [3, 4, 1, 8, -1, -1, -1, 5, -1],

  [-1, -1, -1, 4, 9, 6, -1, -1, -1],
  [2, 7, -1, -1, -1, -1, 9, -1, -1],
  [4, -1, 9, -1, -1, 1, 3, -1, 5],
];

(async () => {
  // function api usage
  const solvedSudoku: number[][] = await solveProperSudokuAsync(puzzleInput2dArr);
})();

example usage to write a visualisation (in the console) of a suduko puzzle being solved in realtime

// sudoku puzzle input as a 2d array (can also be as a 1d array)
const puzzleInput2dArr: number[][] = [
  [9, 1, 5, -1, -1, 3, 4, -1, 6],
  [-1, -1, -1, 1, -1, 2, -1, 8, 9],
  [-1, 6, -1, -1, -1, 4, 7, -1, 3],

  [-1, -1, -1, 3, 1, -1, -1, 9, -1],
  [5, -1, 8, -1, 4, -1, -1, 3, 2],
  [3, 4, 1, 8, -1, -1, -1, 5, -1],

  [-1, -1, -1, 4, 9, 6, -1, -1, -1],
  [2, 7, -1, -1, -1, -1, 9, -1, -1],
  [4, -1, 9, -1, -1, 1, 3, -1, 5],
];

(async () => {
  console.log("sudoku puzzle input");

  const formattedPuzzleInputAsString = puzzleInput2dArr
    .map((row) => row.map((cell) => (cell === -1 ? " " : cell)).join(" "))
    .join("\n");
  console.log(formattedPuzzleInputAsString);

  console.log("\n");

  // function api usage
  const solvedSudoku = await solveProperSudokuAsync(puzzleInput2dArr, {
    // 'hook' into each function call in the recursive call stack
    onFunctionExecutingInCallStack: (x, y, arr2d) => {

      // visualisation code start
      console.clear();
      console.log(`call stack n: ${y * 9 + x}, x: ${x}, y: ${y}`);
      const formattedResultAsString = arr2d
        .map((row) => row.map((cell) => (cell === -1 ? " " : cell)).join(" "))
        .join("\n");
      console.log(formattedResultAsString);
      // visualisation code end

    },

    // update/draw 10 times per second (will wait 1/10 of a second until calling next function in recursive algorithm)
    delayBetweenEachStepInCallStackInMillisecs: 1000 / 10,
  });

  // print result
  console.log("solved sudoku puzzle");
  const formattedResultAsString = solvedSudoku
    ?.map((row) => row.join(" "))
    .join("\n");
  console.log(formattedResultAsString);
})();

API Documentation

Function: solveProperSudokuAsync()

solveProperSudokuAsync(puzzleInput, callStackStep?): Promise<number[][]>

Solves a proper sudoku puzzle (9x9 with a minimum of 17 clues) with a recursive backtracking algorithm

Parameters

puzzleInput

a 9x9 2d array of numbers where -1 represents an empty cell

number[] | number[][]

callStackStep?

CallStackStep

Returns

Promise<number[][]>

a 9x9 2d array of numbers representing the solved sudoku puzzle

projects that use this package

sudoku solver async realtime visualisation web app

If you end up writing any apps/visualisations that use this package, or find the package useful in any way would <3 to see or hear about it @ [email protected] and am happy to link it here. Happy Coding :)