I started to write my own Sudoku solver in Python but it was too slow / inelegant,
so I searched for an elegant way to solve this problem.
I stumbled upon this cryptic Sudoku solver and the very good explanation given by the community: Shortest Sudoku Solver in Python - How does it work?
I have understood the explained and stretched out version but I have one problem with this:
When I run the version explained by Bill Barksdale with a Python version below 3.0 it takes pretty long to solve a Sudoku, but succeeds and prints out the right solution.
When I run the program with Python 3.0 or 3.4, the program is done in less than a second, but prints out a wrong solution.
I have tried to find the problem with Python > 3.0 but I have no idea.
Could someone please point out why this program is running below Python 3.0 but not above?
Thanks
I suspect that the problem may well be the difference in the Python 3 divide operator in Python 2 2/3 = 0
but in Python 3 2/3 = 0.66666
which will mess up the logic nicely. You can try adding from __future__ import division
and running under Python 2 or by replacing all the /
s with //
and running under Python 3.
In general obfuscated code is also unmaintainable code so I would avoid describing it as elegant.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.