JavaScript Sudoku solver fits in a tweet

This site may earn affiliate commissions from the links on this page. Terms of use.

Sudoku is a logic-based puzzle game that sees you trying to figure out the remainder of the 1-9 digits on a 9×9 board. Depending on the difficult of the board and your math skills, they can take you from several minutes to hours to solve.

A puzzle always begs a general solution, though, and Sudoku solvers have been a popular past time for some programmers wanting to test out their skills in any given programming language. Taking it to the extreme and adding a bit of fun is 140byt.es, which challenges willing coders to offer up JavaScript code that solves some problem in 140 bytes, therefore it will fit in a tweet.

Mathieu Henri, also known as P01, is a French web developer and designer. He decided to take up the challenge and came up with a Sudoku solver that would fit in a tweet. You can see the un-annotated program below (click to see full size):

The program accepts an array representing the Sudoku grid and spits out a solved board the other end. This is no easy task even if you don’t have the 140 bytes limit, so to achieve a solution in tweet-friendly form is doubly impressive.

It looks like hitting the 140 byte limit didn’t happen immediately. Some helpful comments on P01’s GitHub post of the original program highlighted where it could be made more efficient. So the total fell from 146 bytes to 145, then 143, and eventually reached an optimal 139 bytes.

If you want to take advantage of the P01’s Sudoku solver, go right ahead. He has released it under the WTFPL, which basically means you can do whatever you want with the code.