-
Description cannot go diagonally
array = [1,1,1,y,1], [1,1,1,1,1], [1,1,x,1,1], [1,1,1,1,1]
here you have to make 3 moves to get from y to x
Code def distance(array): y = 0 y1 = 0 for inner_list in range(len(array)): if "y" in array[inner_list]: y = inner_list if "x" in array[inner_list]: y1 = inner_list x = array[y].index("y") x1 = array[y1].index("x") dist = abs(x -x1) + abs(y-y1) return dist
Test Cases array = [1,1,1,"y",1],[1,1,1,1,1],[1,1,"x",1,1],[1,1,1,1,1] test.assert_equals(distance(array),3) array = [1,1,1,1,"y"],[1,1,1,1,1],[1,1,"x",1,1],[1,1,1,1,1] test.assert_equals(distance(array),4)
Output:
-
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}