https://school.programmers.co.kr/learn/courses/30/lessons/87377
xmax = max(coord_set, key=lambda x:x[0])[0]
x == int(x)
와 같이 조건을 체크해줄 수 있다는 점이다.x
가 아니라 int(x)
를 반환해야 한다. 3.0 == 3 이게 True를 반환하기 때문에, 무조건 정수로 변환해서 반환해야 한다.from itertools import combinations
def solution(line):
INF = int(2e9)
def getPoint(a, b, e, c, d, f):
x_son = b*f - e*d
y_son = e*c - a*f
mother = a*d - b*c
if mother == 0:
return False
x = x_son / mother
y = y_son / mother
if x == int(x) and y == int(y):
return (int(x), int(y))
coord_set = set()
combs = combinations(line, 2)
for comb in combs:
a, b, e = comb[0]
c, d, f = comb[1]
point = getPoint(a, b, e, c, d, f)
if point:
coord_set.add(point)
xmax, xmin = max(coord_set, key=lambda x:x[0])[0], min(coord_set, key=lambda x:x[0])[0]
ymax, ymin = max(coord_set, key=lambda x:x[1])[1], min(coord_set, key=lambda x:x[1])[1]
answer = [['.'] * (xmax-xmin+1) for _ in range(ymax-ymin+1)]
for x, y in coord_set:
answer[ymax-y][x-xmin] = '*'
return [''.join(row) for row in answer]