hi, i have to make a simple sudoku solver, i am done 3/4 of it but i'm having a little trouble on somethings, here is what i've got so far

import copy 
  
def display(A): 
    if A: 
        for i in range(9): 
            for j in range(9): 
                if type(A[i][j]) == type([]): print A[i][j][0], 
                else: print A[i][j], 
            print 
        print 
    else: print A 
  
def has_conflict(A): 
    for i in range(9): 
        for j in range(9): 
            for (x,y) in get_neighbors(i,j): 
                if len(A[i][j])==1 and A[i][j]==A[x][y]: return True 
    return False 
  
def get_neighbors(x,y):    # no idea how to get it or do it 
    return [] 
  
def update(A, i, j, value):  # no idea how to do it 
    return [] 
  
def solve(A):   # not sure if it's coorect 
    return []           
  
  
  
  
A = [] 
infile = open('puzzle1.txt', 'r') 
  
for i in range(9): 
    A += [[]]  
    for j in range(9): 
        num = int(infile.read(2)) 
        if num: A[i] += [[num]] 
        else: A[i] += [[1,2,3,4,5,6,7,8,9]] 
  
for i in range(9): 
    for j in range(9): 
        if len(A[i][j])==1: A = update(A, i,j, A[i][j][0]) 
        if A==[]: break 
    if A==[]: break 
  
if A<>[]: A = solve(A) 
display(A)

so as you can see i did everything except for the def update, and get neighbour. I've tried many times before i post it but just couldn't do it. So if anybody can help me that would be great, also this is due on monday. any help THX

Recommended Answers

All 3 Replies

A dictionary may be a better container than a list of lists. If you give each square a unique number, from 1-81, then the neighbors are simple to find.
square -1 and +1 for this row
square -9 and + 9 for this column
(square -9) -1 and + 1; and (square +9) -1 and +1 for diagonals.

one of the main things it has to be list within list (3d) and recrusive that's why i'm forced to do it this way

any help please finding any of these functions
(solve, update, get_neighbour)

so as you can see i did everything except for the def update, and get neighbour. I've tried many times before i post it but just couldn't do it. So if anybody can help me that would be great, also this is due on monday. any help THX

Wow, you did everything except what wasn't given to us... trying to get random people on the internet to do your assignment for you, I see you will go far in computer science... -_-

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.