Grokking Oracle Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
isValid Question

greenwald.juj

Nov 6, 2023

For the isValid Function, can't you just put it like this instead of having a for loop in it?

def isValid(self, board, row, col, num): '''return True if Valid and False if not valid''' ### NEW VERSION ### - this passes the tests # Check if in ROW if board[row][:] == num: return False # Check if in COL if board[:][col] == num: return False # Check if in 3 x 3 GRID if (board[(row//3)*3 + row//3][(col//3)*3 + col%3] == num): return False return True ### ORIGINAL VERSION ### for x in range(9): # Check if in ROW if board[row][x] == num: return False # Check if in COL if board[x][col] == num: return False # Check if in 3 x 3 GRID if (board[(row//3)*3 + x//3][(col//3)*3 + x%3] == num): return False return True

0

0

Comments
Comments
G
greenwald.juj 2 years ago

The code gets messed up when posting here, so part of it is commented where it should be and not commented where it should be but if you copy and paste this into the console, it will show up correclty.

On this page