Monday, 2 May 2011

Solving Sudokus with Alteryx?

For today's post there has been a slight change of author, Adam suggested I blog about this as it fits in fairly well with some of his unusual applications of Alteryx.

So I guess I should introduce myself to start with, some of you will know me but I guess some of you won’t. Having the same surname as Adam isn’t a coincidence, we’re married and have been for about 4 years now. We both use Alteryx in our working lives and although I don’t quite think about things in the same way as Adam (not sure too many people do!) I also like to see and test what Alteryx is capable of.

A while ago Adam and I tried to solve a puzzle from the New Scientist magazine using Alteryx. The puzzle revolved around being able to solve a Sudoku puzzle. There was obviously slightly more to it than just a Sudoku puzzle but being able to solve the Sudoku was a necessary part of it. We started thinking surely we can do that in Alteryx, Adam in his ever confident fashion, Alteryx can do anything! We soon realised it wasn’t really going to work out, a major problem being that we needed to be able to loop through our methodology. This was several months ago, and recently it come up again. Would we now be able to solve sudoku’s using Alteryx; with the latest version that includes iterative macros it seems like it might be possible!

So below is my attempt to make Alteryx solve sudokus, it does work; but only on ‘simple’ puzzles.

As it turns out there is a lot of methodology behind solving sudokus and although I think it would be possible to write a module which would solve any puzzle (that is solvable) I haven’t actually implemented all the different techniques (yet!). During my investigations on this topic I have come across this website which appears to detail all the different methods needed for solving a Sudoku, there are quite a few and I haven’t read them all but the ones I have seem to be explained quite thoroughly.

My module uses an iterative macro so that it can loop round and solve cells and then run through again and hopefully solve more, until it either has managed to solve the Sudoku or gets to a point where it is never going to be able to solve it. (If it can't solve at least one cell per run through then it is not making progress and will never be able to solve it, hence the iterative macro is limited to 80 runs through.) Although it would have been nice to be able to produce something which can solve any puzzle, at the moment this is the best I’ve got, I may add to it over time but in the mean time it has been a good learning experience for getting to know iterative macros. (And it’s given my brain a work out trying to
logically think how to go about solving a Sudoku in Alteryx!)

Hope you’ve enjoyed this somewhat pointless blog post and if anyone else wants to have a guest spot on Adam’s UK Alteryx blog then just get in touch with him.