Posts: 5
Threads: 1
Joined: Oct 2019
A map is given to me in a form of this
WWWTWWWTTT
WWTTTWWWWW
WWWTWWWWWT
The treasure is located at the center of the cross of T's for which the case is (1,3)
The coordinate format is (row,column)
How do I find that exact coordinate of the treasure
Posts: 5
Threads: 1
Joined: Oct 2019
How do I code it in a way it will find the center of T and returns its coordinates
Posts: 4,220
Threads: 97
Joined: Sep 2016
What have you tried? We're not big on writing code for people here, but we would be happy to help you fix your code when you run into problems. When you do run into problems, please post your code in Python tags, and clearly explain the problem you are having, including the full text of any errors.
Posts: 5
Threads: 1
Joined: Oct 2019
def find_treasure(mapfile):
with open(mapfile,'r')as column:
for i, row in enumerate(column):
for j, val in enumerate(row):
if val == 'T':
print(i,j) I can only manage to find all the coordinates for T, i dk how to set a condition such that it returns only the treasure coordinate when it is surrounded by T's
Posts: 4,220
Threads: 97
Joined: Sep 2016
Don't think about writing the code for the condition yet. Think about what the condition is. If you have a T at i, j, what other T's do you need (in terms of i and j) to be the treasure?
Posts: 5
Threads: 1
Joined: Oct 2019
What I am thinking is that for that specific T coordinate, i compare it to (i-1,j),(i+1,j),(i,j-1) and (i,j+1) if all those coordinates shows 'T' it means that (i,j) is the treasure location
Posts: 4,220
Threads: 97
Joined: Sep 2016
So if one condition is column[i - 1][j] == 'T' , how are you going to check all four conditions?
Posts: 5
Threads: 1
Joined: Oct 2019
My guess is create a list to store all the T coordinate
Then run through each of the coordinate, if (i-1,j),(i+1,j),(i,j-1) and (i,j+1) are also inside the list then return (i,j)
|