Shortest Sudoku Solver in Python - How does it work?

前端 未结 5 1695
情话喂你
情话喂你 2020-12-04 05:04

I was playing around with my own Sudoku solver and was looking for some pointers to good and fast design when I came across this:

def r(a):i=a.find(\'0\');~i         


        
5条回答
  •  悲&欢浪女
    2020-12-04 05:09

    The code doesn't actually work. You can test it yourself. Here is a sample unsolved sudoku puzzle:

    807000003602080000000200900040005001000798000200100070004003000000040108300000506

    You can use this website (http://www.sudokuwiki.org/sudoku.htm), click on import puzzle and simply copy the above string. The output of the python program is: 817311213622482322131224934443535441555798655266156777774663869988847188399979596

    which does not correspond to the solution. In fact you can already see a contradiction, two 1s in the first row.

提交回复
热议问题