2023-12-15 11:17:25 +02:00
|
|
|
def checksouth(x, y):
|
|
|
|
|
print('south')
|
2023-12-15 11:34:12 +02:00
|
|
|
if x < (len(ruum)-2):
|
|
|
|
|
if ruum[x+1][y] in ('|JL'):
|
|
|
|
|
return True
|
|
|
|
|
return False
|
2023-12-15 11:17:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def checknorth(x, y):
|
2023-12-15 11:34:12 +02:00
|
|
|
print('north')
|
|
|
|
|
if x > 0:
|
|
|
|
|
if ruum[x-1][y] in ('|7F'):
|
|
|
|
|
return True
|
|
|
|
|
return False
|
2023-12-15 11:17:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def checkwest(x, y):
|
2023-12-15 11:34:12 +02:00
|
|
|
print('west')
|
|
|
|
|
if y > 0:
|
|
|
|
|
if ruum[x][y-1] in ('-LF'):
|
|
|
|
|
return True
|
|
|
|
|
return False
|
2023-12-15 11:17:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def checkeast(x, y):
|
|
|
|
|
print('south')
|
2023-12-15 11:34:12 +02:00
|
|
|
if y < (len(ruum[x]) - 2):
|
|
|
|
|
if ruum[x][y+1] in ('-J7'):
|
|
|
|
|
return True
|
|
|
|
|
return False
|
2023-12-15 11:17:25 +02:00
|
|
|
|
|
|
|
|
|
2023-12-11 19:05:07 +02:00
|
|
|
def otsing(x, y, tase):
|
2023-12-15 11:17:25 +02:00
|
|
|
if ruum[x][y] == 'S':
|
|
|
|
|
checknorth(x, y)
|
|
|
|
|
checksouth(x, y)
|
|
|
|
|
checkwest(x, y)
|
|
|
|
|
checkeast(x, y)
|
|
|
|
|
if ruum[x][y] == "|":
|
|
|
|
|
checknorth(x, y)
|
|
|
|
|
checksouth(x, y)
|
|
|
|
|
if ruum[x][y] == "-":
|
|
|
|
|
checkeast(x, y)
|
|
|
|
|
checkwest(x, y)
|
|
|
|
|
if ruum[x][y] == "L":
|
|
|
|
|
checknorth(x, y)
|
|
|
|
|
checkeast(x, y)
|
|
|
|
|
if ruum[x][y] == "J":
|
|
|
|
|
checknorth(x, y)
|
|
|
|
|
checkwest(x, y)
|
|
|
|
|
if ruum[x][y] == "F":
|
|
|
|
|
checksouth(x, y)
|
|
|
|
|
checkwest(x, y)
|
|
|
|
|
if ruum[x][y] == "7":
|
|
|
|
|
checksouth(x, y)
|
|
|
|
|
checkwest(x, y)
|
2023-12-11 19:05:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
with open("data.txt") as file:
|
|
|
|
|
lines = [line.rstrip() for line in file]
|
|
|
|
|
|
|
|
|
|
ruum = []
|
2023-12-15 11:17:25 +02:00
|
|
|
leitud = []
|
2023-12-11 19:05:07 +02:00
|
|
|
for line in lines:
|
|
|
|
|
ruum.append([*line])
|
2023-12-15 11:17:25 +02:00
|
|
|
leitud.append([*line])
|
2023-12-11 19:05:07 +02:00
|
|
|
|
|
|
|
|
print(ruum)
|
|
|
|
|
|
2023-12-15 11:17:25 +02:00
|
|
|
leitud = False
|
2023-12-11 19:05:07 +02:00
|
|
|
for x, rida in enumerate(ruum):
|
|
|
|
|
for y, koht in enumerate(rida):
|
|
|
|
|
print(f"x={x}, y={y}, koht={koht}")
|
2023-12-15 11:17:25 +02:00
|
|
|
if koht == 'S':
|
2023-12-13 15:40:05 +02:00
|
|
|
otsing(x, y, 0)
|
2023-12-15 11:17:25 +02:00
|
|
|
leitud = True
|
2023-12-13 15:40:05 +02:00
|
|
|
break
|
2023-12-11 19:05:07 +02:00
|
|
|
if leitud:
|
|
|
|
|
break
|