+ 2

2D Map solution problem

https://code.sololearn.com/ch1jPmjW468A/?ref=app My solution fails one of the tests but I can't figure out why. Can anyone please suggest what scenario could make it fail? Thank you.

5th Jan 2020, 10:12 AM
Tom Adamczyk
Tom Adamczyk - avatar
8 Respostas
+ 4
I literally just realized that as well. X2 by definition will always be bigger, made the same silly assumption for Y. Simple IF solved it. Thanks!
5th Jan 2020, 10:22 AM
Tom Adamczyk
Tom Adamczyk - avatar
+ 3
In code 1 case error
2nd Jun 2020, 9:15 AM
SAN
SAN - avatar
+ 2
import numpy as np map = input().split(',') matrix = [list(map[i]) for i in range(len(map))] a = np.array(matrix) b = np.where(a=='P') x2, x1, y2, y1 = b[0][1],b[0][0],b[1][1],b[1][0] dist = abs(x2 - x1) + abs(y2 - y1) print(dist)
14th Dec 2021, 4:56 PM
Mateo González Bufi
Mateo González Bufi - avatar
17th Dec 2021, 9:42 AM
Almantas Seikis
Almantas Seikis - avatar
0
My solution od this task: import re maps = list(enumerate(re.sub("," , "", input()))) position = [] coordinates = [] for pos, letter in maps: if letter == "P": position.append(pos) for numbers in position: x = numbers // 5 y = numbers % 5 coordinate = [x,y] coordinates.append(coordinate) steps = abs(coordinates[0][0] - coordinates[1][0]) + abs(coordinates[0][1] - coordinates[1][1]) print(steps) How can I write it shorter?
11th Apr 2022, 4:07 PM
Przemysław Komański
Przemysław Komański - avatar
0
coord = input() char_count = 0 row_count = 1 col_count = 1 p_coord1 = [[],[]] p_coord2 = [[],[]] for i in range(len(coord)): if coord[i].isalpha(): char_count += 1 if coord[i].lower() == "p": if len(p_coord1[0]) == 0: p_coord1[1].append(int(row_count)) p_coord1[0].append(int(col_count )) else: p_coord2[1].append(int(row_count)) p_coord2[0].append(int(col_count)) row_count += 1 if char_count == 5: char_count = 0 col_count += 1 row_count = 1 distance_between = ((p_coord1[0][0] - p_coord2[0][0])*-1) + ((p_coord1[1][0] - p_coord2[1][0])*-1) print(distance_between) I solved all of the cases but one, what is the problem? I think it should work in all of the cases unless the input format is different. Could you assist me please?
26th Apr 2023, 12:08 PM
Emek Safak
Emek Safak - avatar
0
I sorted it that way: map = input().split(",") a=[] b=[] for x in range(len(map[0])): for y in range(len(map)): if map[x][y] == "P": a.append(x) b.append(y) c=(max(a)-min(a))+(max(b)-min(b)) print(c)
27th Oct 2023, 7:00 PM
Sebastian Kuzma
Sebastian Kuzma - avatar