Sudoku Solver

A web page which solves Sudoku puzzles, implemented in vanilla JavaScript

This was one of the first projects I published back in 2017. It was the time when React had started gaining ground against Angular, and jQuery was still at its prime. However, I decided to use vanilla JavaScript in order to teach myself the basics of the language.

The implementation is a combination of DOM manipulation functionality, ES5 classes and a problem solving algorithm. Fun fact, I initially implemented the solution in C! To use the app, one had to manually input each Sudoku cell in the console (not much fun). The main reasons for this choice were my familiarity with the language and performance concerns.

Luckily, a more experienced developer and my mentor at the time pointed out that

  • My application would be more usable with a GUI
  • For a project like this, there is no point addressing performance proactively

At this point you would expect me to quote

Premature optimization is the root of all evil
> Donald Knuth - The Art of Computer Programming, 1974

Of course, he was spot on! The JavaScript implementation is super fast from a user perspective (no measurements taken). It would be interesting to see how the performance scales for larger matrices (eg 15 x 15 instead of 9 x 9) 🤓

My emphasis on performance at the time, characteristic of developers straight out of university, manifested itself in one more area. The algorithm I implemented is a combination of

  1. Heuristics for extracting cell values based on the given cells, similar to what a Sudoku player would do
  2. A brute force algorithm to calculate the rest

It may be the case that the first approach is redundant, and the second is performant enough for all use cases. Anyway, I really enjoyed implementing the heuristics so it was worth it!

This was also my first exposure to tests. I used some Sudoku (Sudokus ?) of various difficulties to verify that my algorithm was correct. Those are integration tests essentially, but with no testing framework.

Future Improvements 🚀

  • Use React
  • Make the app responsive and mobile friendly
  • Improve the styling of the app (colors/design)
  • Rewrite the tests using a testing framework (jest or mocha)