# Sudoku

Sudoku puzzles are fun to solve, but cost me a lot of time.
I am not a fast sudoku solver. But still, every day the 
[NRC](https://www.nrc.nl/) confronts me with a sudoku, 
to be more precise, a [windoku](https://www.sudokuwiki.org/windoku.aspx).

To spare time, I decided to create a sudoku solver, knowing that there
are very many solvers around, also in the public domain. Using an
existing solver would be cheating so I had to write one myself. 

To make a difference I wrote the thing in Fortran 
thus refreshing my knowledge of array syntax, subarrays and pointers. (By the way,
using Fortran led to a small but significant improvement in [findent](/findent)).

To my surprise, the solver was very easy to write and small in size:
the kernel
itself takes 20 lines of uncomplicated code. Of course, more code was needed for
I/O and checking the validity of the content of
a cell. 

The program, using a brute force approach, combined with some trivia.
It is capable to solve sudoku's in a few milliseconds.

Btw: a real fast solver is available as [tdoku](https://github.com/t-dillon/tdoku){target="_blank"}.

## Download

Current version: YYYversionZZZ

The code is available as a [tar ball](YYYdZZZ/sudoku/wsudoku-YYYversionZZZ.tar.gz).

## Compiling and usage
Make sure you have a Fortran compiler available, for example `gfortran`. 
Download the tar ball and enter the following commands:

     tar xf wsudoku-YYYversionZZZ.tar.gz
     cd wsudoku-YYYversionZZZ
     make fsudoku

Then, run the solver by:

     ./fsudoku < std4.txt

A number of test cases is available as *.txt files. The file fsudoku.f90 starts 
with a description of the input format.

## Back in time ...

Just for fun, I created also a Fortran-66 variety of the program:

      make fsudoku66
      ./fsudoku66 < std4.txt

## Solving sudoku's on your screen

Included in the tar ball is some software that enables one to solve sudoku's
presented on the web using the script wsudoku-solver. After installation,
the script should be available in the games-section. To use it,
open a web page with a sudoku puzzle, activate the script by clicking
the icon and follow the instructions. 

The program is able to solve any easy interpretable sudoku presented on your screen, 
for example, the sudoku's generated by gnome-sudoku, but not the sudoku's of ksudoku.

The program works as follows:

* locate the sudoku on the screen
* read the numbers by using tesseract, trained to recognise 
  [digits](https://github.com/Shreeshrii/tessdata_shreetest/blob/master/digits.traineddata)
  (that is why the tarball is so large)
* call fsudoku
* if requested, fill in the sudoku

**Installation:**

     tar xf wsudoku-YYYversionZZZ.tar.gz
     cd wsudoku-YYYversionZZZ
     # See the file README for prerequisites.
     # I am not sure all prerequisites are mentioned. To be sure, run
     # the script in a terminal and observe the error messages.
     make
     sudo make install

If the program's icon is not visible under games,
try to install in ``/usr``, in stead of ``/usr/local`` by adapting
the Makefile.
     
## Sudoku's on the web

Below you find a list of some of the sudoku web sites. 
I observed that some websites are using an unreasonable amount of CPU power
while presenting the puzzle. This could be caused 
by strange programming techniques, but it could also be
that my PC takes part in bitcoin mining or something like that.

| URL | comments |
|-----|----------|
|&nbsp; [sudoku-puzzles.net](https://sudoku-puzzles.net/){target="_blank"} &nbsp;|&nbsp; Many sudoku variants, CPU intensive. &nbsp;|
|&nbsp; [websudoku.com](https://www.websudoku.com/){target="_blank"} &nbsp;||
|&nbsp; [puzzelstad.nl](https://www.puzzelstad.nl/sudoku-dagelijks/dag_sudoku.php){target="_blank"} &nbsp;||
|&nbsp; [sudoku.com](https://sudoku.com/){target="_blank"} &nbsp;||
|&nbsp; [microsoft-sudoku](https://www.msn.com/nl-nl/play/games/microsoft-sudoku/cg-mssudoku){target="_blank"} &nbsp;|&nbsp; Does not run in Firefox. Runs in Chromium, is a CPU eater. &nbsp;|
|&nbsp; [pzzl.com](https://www.pzzl.com/){target="_blank"} &nbsp;|&nbsp; Windoku's and sudoku's &nbsp;|
|&nbsp; [nieuwsblad.be](https://www.nieuwsblad.be/sudoku){target="_blank"} &nbsp;||
|&nbsp; [sudoku2.com](https://sudoku2.com/play-the-hardest-sudoku-in-the-world/){target="_blank"} &nbsp;|&nbsp; The hardest sudoku in the world? &nbsp;|
|&nbsp; [sudokuhit.com](https://sudokuhit.com/){target="_blank"} &nbsp;|&nbsp; Sudoku's have more than one solution. &nbsp;|
|&nbsp; [sudokuoftheday.co.uk](http://www.sudokuoftheday.co.uk/){target="_blank"} &nbsp;||
|&nbsp; [https://www.7sudoku.com/](https://www.7sudoku.com/){target="_blank"} &nbsp;|&nbsp; Do NOT click empty cell, choose method A for fill-in.|
|&nbsp; [extremesudoku.info](https://www.extremesudoku.info/){target="_blank"} &nbsp;||
|&nbsp; [sudoku-space.com](http://www.sudoku-space.com/){target="_blank"} &nbsp;|&nbsp; Presents also X-sudoku's and windokus (a.k.a. hyper sudoku's).|
|&nbsp; [sudokuexchange.com](https://sudokuexchange.com/){target="_blank"} &nbsp;|&nbsp; Sudoku's of different levels.|

