I'm not very familiar with python, so can you please tell me which improvements can be done here?
Thanks.
def in_range(grid, state):
if state[0] >= 0 and state[1] >= 0 and state[0] < len(grid) and state[1] < len(grid[state[0]]):
return True
return False
def search():
# ----------------------------------------
# insert code here and make sure it returns the appropriate result
# ----------------------------------------
state = [0] + init
marked = []
for i in xrange(len(grid)):
marked.append([0]*len(grid[i]))
marked[state[1]][state[2]] = 1
expanded = [state]
while len(expanded) > 0:
expanded.sort(lambda a, b: b[0] - a[0])
state = expanded.pop()
if goal == [state[1], state[2]]:
print state
return
for i in xrange(len(delta)):
x = state[1] + delta[i][0]
y = state[2] + delta[i][1]
if in_range(grid, [x, y]) and grid[x][y] != 1 and marked[x][y] != 1:
expanded.append([state[0] + cost, x, y])
marked[x][y] = 1
print 'fail'
asked
13 Mar '12, 04:20
Alexander Gr...
177●3●7●17
accept rate:
55%