
From Crutches to Bijection: How I Wrote a Sudoku Generator in JS
Hi there. I’m a math and computer science teacher in sunny Thailand. During the school holidays, instead of my usual trips around Asia, I decided to entertain myself by diving into JavaScript syntax. Once upon a time, my wonderful (now ex) wife and I were huge fans of non-standard Sudoku with “greater-than/less-than” signs. We used to print unique grids for ourselves, and sometimes I even drew them by hand from templates I found online. In this article I want to tell the story of how my mathematical Sudoku grid generator evolved, from naive array shuffling to strict combinatorics and a full factorial number system. Version 1. Naive shuffling The idea behind the first version was ridiculously simple. Why generate a grid from scratch by solving an NP-complete backtracking problem when you can just take one ready-made, 100 % valid grid and shuffle it really well? The rules of classic Sudoku allow several geometric transformations that don’t break the logic: Swap any two rows inside the sa
Continue reading on Dev.to JavaScript
Opens in a new tab


