-
Code def distance(a): y,y1 = 0,0 for i in range(len(a)): if "y" in a[i]: y = i if "x" in a[i]: y1 = i x ,x1 = a[y].index("y"), a[y1].index("x") return abs(x -x1) + abs(y-y1)
Preloaded Code 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) array = [1,1,1,1,"y",1,1],[1,1,1,1,"x",1,1],[1,1,1,1,1,1,1],[1,1,1,1,1,1,1],[1,1,1,1,1,1,1],[1,1,1,1,1,1,1] test.assert_equals(distance(array),1) array = [1,"y",1],[1,1,1],[1,1,"x"] test.assert_equals(distance(array),3)
Output:
-
Code def distance(array):for i in range(len(array)):if "y" in array[i] : y = abs(array[i].index("y") - i)if "x" in array[i] : x = abs(array[i].index("x") - i)return (x+y)- def distance(a):
- y,y1 = 0,0
- for i in range(len(a)):
- if "y" in a[i]: y = i
- if "x" in a[i]: y1 = i
- x ,x1 = a[y].index("y"), a[y1].index("x")
- return abs(x -x1) + abs(y-y1)
- 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 }}