rendered paste bodyimport Numeric
def knight_travel(size,start_x,start_y):
array = Numeric.zeros([size,size])
poss_moves = [[2,-1],[2,1],[-2,1],[-2,-1],[1,2],[-1,2],[1,-2],[-1,-2]]
history = []
curr_x = start_x
curr_y = start_y
num_moves=1
while num_moves <= size*size:
for move in poss_moves:
move_x=curr_x+move[0]
move_y=curr_y+move[1]
if move_x>=0 and move_x<size and move_y>=0 and move_y<size and array[move_x][move_y]==0:
print "Move: ", num_moves
print array
curr_x=move_x
curr_y=move_y
array[move_x][move_y] = 1
history.append([curr_x,curr_y])
num_moves+=1
break
else:
curr_x,curr_y = history.pop()
knight_travel(8,0,0)