Sudoku Fever, the Python Variation

For the past several weeks I have been using python, solving Project Euler challenge questions. My skill was growing to intermediate level, until I fell under the spell of the Sudoku puzzle. Develop a python program to solve 50 initial positions.

I have spent more time on the Sudoku puzzle than on all the other puzzles, but I think the crisis has passed.  I have moments when I’m starting to think of other things.  A nibble of a story idea.  The recollection that I must do things around the house. 

But two-thirds of my dreamtime remains, how do I parse easily through the subgrid of the Sudoku board? Unfortunately the dream fragment is a recurrent loop, only occasionally interrupted by a winsome woman.

I received Numerical Analysis (with python) in the mail yesterday.  I have broadened my python to numpy and I’m more than a third through Thinking Python. I am breaking free of the Sudoku cycle.

What bothers me about this fever is that my flailing about, my difficulty in converting my manual Sudoku algorithms into python code is that it is an indication that my mind is slipping, losing its ability to think abstractly, to convert my ideas into program code.

But then I recall that this feeling is similar to 25 years ago when I had to reverse engineer the MD tax programs based on the PA tax programs, because the source code had been destroyed in the flooding of the data center.

Sudoku Board

The Sudoku board also has the dubious advantage of being able to be approached as a string, a list, or a numpy array.  I started with a string, segued to lists, got 39 of 50 boards solved that way.  In the solutions, the lists morphed into tuples of availCells.  The maintenance of the availCells (updating with information) as I discovered new forced digits was uncertain.

I went in circles for awhile, then took some time to reassess the situation.  Started Thinking Python from the beginning, documenting features in short programs for myself.  Doing the exercises.  Seeing some misconceptions I had, that some around-the-barn techniques I’d developed could be done much simpler, and surprising one around the barn technique, which I was always trying to improve was the approved Python way to traverse the list.  And I heard about numpy and arrays, which are a more natural fit for the Sudoku board.  I spent time and effort doing its tutorial.

Finally I did a board elimination program using arrays in numpy.  That worked, but it only had row, col, and subgrid slot at a time logic.  No special logic like I already had working for lists.  So the dilemma was – add that special logic to the array before I could add new logic to solve the remaining 11 boards or go back to the list logic and add new logic there.  I decided to go back to list and tuples and add new logic.

I will add to my table of useful List operations, so I can compare them to the numpy array list.  I have to write it myself, because my memory has such a labile programming flexibility that when I’m using lists those operations seem to encompass the programming world.  Similarly for arrays, with the upshot that I don’t have a clear understanding of the tradeoffs between them.

The fact that I’ve just spent 30 minutes typing this up is a indication that my interest is nearly sated in the Sudoku – but since I established it as an interest, in Project Euler – I don’t want to leave it incomplete.

When I do finish Sudoku (or with Sudoku), I will glance through Euler list for other intriguing problems that my increased knowledge of Python might let me attack more nimbly.

I must also remind myself. I only advanced in solving this problem when I developed a better terminology describing the Sudoku board and actions.  Enforcing consistency for names in program freed a layer of thoughts, from name translation to deduction.  Also until then, ambiguities in casual Sudoku thoughts existed, because the mind is so labile in multiple contexts.

Hurrah! Got all 50 boards solved a few days ago. Now I can truly move on.

Image of Sudoku board by LithiumFlash, CC BY-SA 4.0, via Wikimedia Commons


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

You May Have Missed