python - Am I cheating on this AI challenge? -
so on hackerrank under ai section, solution "bot saves princess - 2" problem reads input princess's position. solution supposed that? don't see how else can solved efficiently.
problem:https://www.hackerrank.com/challenges/saveprincess2
solutiondef nextmove(r,c, pr, pc): if r < pr: r += 1 return("down") elif r > pr: r -= 1 return("up") if c < pc: c += 1 return("right") elif c > pc: c -= 1 return("left") n = int(input()) r,c = [int(i) in input().strip().split()] grid = [] pr = 0 pc = 0 in range(0, n): inp = input() if inp.find('p') >= 0: pr = pc = inp.find('p') grid.append(inp) print(nextmove(r,c,pr, pc))
forgive me if mistaken, can not find princesses position finding index of 'p' in grid, not seem specified input:
def find_princess(grid): n = len(grid) in range(grid): j in range(grid): if grid[i][j] == 'p' homecoming i,j
python algorithm artificial-intelligence
No comments:
Post a Comment