Discussion on: Critique My Code: Sudoku Solver in Go

zenmumbler profile image

I did not look too deeply into the code, but two things jumped out to me.

1) Allocating memory inside (tight) loops should be avoided.
You're creating a lot of Cell objects and arrays for each iteration, try to revise it that you have (most of) the memory and objects you need up front. This goes hand in hand with…

2) By making the Cell type the primary actor of the solving algorithm, each Cell has to recreate its own vision of the world (i.e. the puzzle) from the inside out. If you move the controlling code from the data element to the data container, you can avoid a lot of redundant work. The container knows about all the cells and their layout, best to use that knowledge on that level of abstraction instead of ignoring that information and recreating it for each element. (This is a pretty common OOP-originated performance counter-pattern)

I made a simple implementation and an optimized version of it in a webpage and also put the code in a Gist, check it out and please let me know if this was useful to you. It's JavaScript but hopefully still understandable.

Gist: gist.github.com/zenmumbler/96dcc5e...
Page: zenmumbler.net/suso/

mas profile image
Sam P Author

Thank you. You present some very valid criticisms and I'll try and iron them out soon.