Sunday, 27 February 2022

Creating a Book of Sudoku Puzzles

I started looking into this some time ago.

At first I tried pasting images into a document on my Google drive. After I had added 21 puzzles with their corresponding solutions, I realised this was going to take far too long so I decided to automate the process.

In puzzle 641 I showed how I could use Python to create a PDF containing a sudoku puzzle and its solution.

The next step was to make a file of puzzles and solutions to use as input for this program. Using a simple Linux bash script I ran my sudoku creation C program in a loop and graded each puzzle it created using Hodoku. I left it running until it had written 100 easy puzzles into a file. You can see this file in the screen print below. Unfortunately the screen of the laptop I used was small so the lines wrapped round a bit but you should be able to get the idea of what I did:


At the start of each line is the puzzle number i.e. 1, 2, 3 etc.

Then there is a space. I'm not a Python expert (yet) but that space probably won't be necessary for the program I write to produce the PDF of 100 puzzles. I just added it to make this post easy to explain.

Then there is the puzzle, represented as 81 digits, followed by another space.

The solution comes next. It's on the same line in the file but it wraps round on the screen print.

I now just need to write the program which will render the puzzles in the book.

It may end up being two programs:

One program to create a PDF which I will give away for free with some advertising on each page. That depends on finding a suitable advertiser. Don't all rush at once.

Trying to sell a PDF is probably a waste of time as it will be plagiarized straight away. It seems that every day I receive an offer to download some free book about Cyber Security, Linux or Networking. These books typically contain high quality content so the idea that their authors intended to give them away for free seems absurd. It is far more likely that they were stolen and are being offered for nothing to build email lists or possibly to download malware.

Another program to create a PDF which will become a paperback to sell on Amazon. There are a couple of issues with this: There are thousands of sudoku books already so competition is high. Also, I don't have a publisher so the books will have to be printed on demand which will push the price up.

Tuesday, 22 February 2022

Pattern Repetition in Sudoku Puzzles

There seems to be pattern repetition in all standard sudoku puzzles. You can see what I mean in the answer to puzzle 644, which I published recently:

There is a 7 and 3 at the top of column 1. There is another 7 and 3 at the bottom of column 2 and the last 7 and 3 is in the middle of column 3.

The same goes for 8 and 2. They appear to the left of row 4, in the centre of row 5 and to the right of row 6.

You don't have to look very carefully to see that this pattern repetition covers the whole puzzle.

However, sometimes this pattern repetition goes too far (IMHO). You can see what I mean in the solution below. I created it recently but will not be using it to produce a puzzle:

1, 6 and 8 appear together to the left of row 7, in the middle of row 8 and to the right of row 9.

2, 7 and 9 are similarly repeated, as are 3, 4 and 5.

3, 8 and 9 appear at the top of column 7, in the centre of column 8 and at the bottom of column 9.

2, 4 and 6 are repeated in the same way, as are 1, 5 and 7.

I first noticed this in one of my puzzles some time ago and assumed my creation program had a bug. Further investigation showed that puzzles with solutions like this are used widely.

Personally I don't like it and up to now I have checked for pattern repetition like this before using a solution on my blog.

This has been possible because I only post puzzles from time to time.

However, for some time now I have been looking into the technology behind publishing a paperback book of puzzles. The idea of having to check a large number of puzzles before using them does not appeal to me. I have now changed my puzzle creation program to check for this type of pattern repetition and backtrack whenever it is present in the solution.

Sunday, 20 February 2022

How To Use DCODE To Show Multiple Solutions for a Sudoku Puzzle

A sudoku puzzle should have exactly one solution. Unfortunately there are many apps, web sites and books which show puzzles with more than one answer.

A new member joined my Sudoku Puzzles Facebook group recently and advertised a book he was selling on Amazon. I asked him to show us a sample puzzle and he sent quite a few. However, several of them had multiple solutions.

When this was brought to his attention, he did not seem to believe us as he had apparently paid to use the program which created his puzzles.

In cases such as this, you may have to show the multiple solutions to prove your point.

You can do this here. Key in the puzzle in the central grid, select the COMPUTE ALL SOLUTIONS button then click the > SOLVE SUDOKU box. The solution(s) will appear down the left hand side of the screen:

Solution to Sudoku no 644

Sudoku no 644 (Diabolical)

Solve online

Sudoku grader and solver

See answer

Tuesday, 15 February 2022

Solution to Real Word Gogen no 8

Here is my version of the answer:

Bass from Stack Exchange solved it as follows:

Deductions used:

  • E is next to both D and L, so it can be placed.

  • R is next to E, and it needs to be able to reach the B in ROB, so the R is placed.

  • A is next to M, and it must have at least 4 unknown neighbours to house all of C,X,N and H. So the A is placed.

  • with CXNH around the A, ACQUIRE won't fit onto the three top rows anymore, so the C is placed.

  • Now WHAM places the H

  • AXLE disambiguates the N and X around the A

  • U must be adjacent to C, J and S, so it's placed.

  • ACQUIRE now places the Q and I

  • the T in JUST is now forced

  • P must be adjacent to both I and R, so it is placed

  • O in ROB is now forced

  • which in turn forces the V in derv (which is some sort of diesel vehicle, it seems)

  • the K in KEG has only one spot left

  • and even without using the remaining clue (FIR) we know the final empty spot must house the final missing letter, F.

The only part of this explanation I did not follow at first was how the puzzle could be solved without using the word FIR as a clue. I create these puzzles manually, which can take up to a couple of hours. Then I check that there is exactly one solution using a C program, which I wrote myself. As part of this process, I remove each word and only retain it as a clue if it is required to produce a unique solution. I had forgotten that my program checks that every letter from A to Y is included at least once in the clues. If there are any missing letters, the program halts tidily and does not proceed to look for a unique solution. I may now decide to change it so that it allows a maximum of one missing letter in the clues then places that letter at the end if there is only one place it can go.

It would be good to know what the Evening Standard does for their own gogen puzzles but unfortunately they never answer when I write to them. I may just have to go to London for a few days to collect some copies of the Evening Standard and try out their gogen puzzles again myself.

Real Word Gogen no 8

Add the 25 letters between A and Y to the grid above. Each one should appear exactly once. When you have finished, you must be able to spell the following words moving horizontally, vertically or diagonally around the grid:

ACQUIRE, AXLE, CUT, DERV, FIR, JUST, KEG, MAN, PILE, PRY, ROB, WHAM.

See the answer 

Points to note for the future:

When I first made one of these puzzles, I used some image creation software on my Google drive. For some reason I was unable to get all the connections to line up. Our younger son said that people would not like this but I went ahead anyway. I recently shared this example on Stack Exchange and an Ivo Beckers said the same thing (as usual, click on the image to enlarge it and bring it into focus if necessary):


Somebody by the name of Bass suggested the following layout, which I will use from now on:

I will also be using the empty grid provided by Bass for future gogen puzzles on this blog.

Monday, 14 February 2022

Solution to Sudoku no 641

Here is the solution, which I put on the 2nd page of the same PDF file:

...and here it is in the format I normally use:

Sunday, 13 February 2022

Sudoku no 641 (Easy)

I have been able to create and grade sudoku puzzles in bulk for some time now. However, I have always had to render them in a grid one by one using an online sudoku application. This has restricted me to producing a few puzzles, which I display on this blog.

I recently worked out how to render my puzzles in a standard grid using a Python program, which can then write them out to a PDF file. This should eventually allow me to produce PDF files containing hundreds of sudoku puzzles, which I will offer for sale elsewhere on the Internet.

You can see the first puzzle I created in this way below. Click on the image to enlarge it / bring it into focus if necessary:

Here is the same puzzle in the format I normally use:


Solve online 

Sudoku grader and solver 

See the answer

Solution to Sudoku no 640

Sudoku no 640 (Diabolical)

Solve online 

Sudoku grader and solver 

See the answer