Python Forum
Sudoku Solver in Python - Can someone explain this code ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sudoku Solver in Python - Can someone explain this code ?
#4
def Suduko(grid, row, col):
 
    if (row == M - 1 and col == M):
        return True
    if col == M:
        row += 1
        col = 0
    if grid[row][col] > 0:
        return Suduko(grid, row, col + 1)
    for num in range(1, M + 1, 1): 
     
        if solve(grid, row, col, num):
         
            grid[row][col] = num            
            if Suduko(grid, row, col + 1):
                return True
        grid[row][col] = 0
    return False


I am not sure if we are using row=0 and col=0 as starting or row=1,col=1 as starting
In this code the Row = 8 and Col=9 because M=9
so if we see the picture attached.

suduko rows and column

so we still have one more Row left at the bottom - how will that be processes?


so basically we have two functions suduko and solve
I am trying to study what exactly each doing.[Image: lzlLd4k]

Attached Files

Thumbnail(s)
   
Reply


Messages In This Thread
RE: Sudoku Solver in Python - Can someone explain this code ? - by qwemx - Jun-25-2022, 12:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Explain the python code in this definition Led_Zeppelin 1 773 Jan-13-2023, 10:20 PM
Last Post: deanhystad
  I am new to python and Could someone please explain how this below code is working? kartheekdas 2 1,054 Dec-19-2022, 05:24 PM
Last Post: kartheekdas
  Explain the python code in this definition Led_Zeppelin 1 1,131 Oct-27-2022, 04:04 AM
Last Post: deanhystad
  Can someone explain this small snippet of code like I am a 5 year old? PythonNPC 3 1,291 Apr-08-2022, 05:54 PM
Last Post: deanhystad
  Could you explain each part of the code? Tsushida 2 1,552 Mar-20-2022, 08:19 AM
Last Post: Larz60+
  Sudoku Solver, please help to solve a problem. AdithyaR 5 2,174 Oct-28-2021, 03:15 PM
Last Post: deanhystad
  building a sudoku solver usercat123 7 2,851 Oct-01-2021, 08:57 PM
Last Post: deanhystad
  What is the run time complexity of this code and please explain? samlee916 2 2,330 Nov-06-2020, 02:37 PM
Last Post: deanhystad
  poplib - parsing message body, could somebody please help explain this code t4keheart 2 2,339 Oct-12-2020, 01:59 PM
Last Post: t4keheart
  unable to use result of solver in another function ross1993hall 0 1,430 Aug-10-2020, 10:29 AM
Last Post: ross1993hall

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020