title: "[프로그래머스] 교점에 별 만들기 Python 파이썬 해설 (Level 2) - 이도훈"
cleanUrl: "programmers/87377"
description: "프로그래머스 Level 2 문제 [교점에 별 만들기]의 풀이를 정리합니다."
import itertools
def solution(line):
points = []
for (a, b, e), (c, d, f) in itertools.combinations(line, 2):
if a*d - b*c == 0:
continue
x = (b*f - e*d) / (a*d - b*c)
y = (e*c - a*f) / (a*d - b*c)
if x.is_integer() and y.is_integer():
points.append([int(x), int(y)])
minx, maxx = min(p[0] for p in points), max(p[0] for p in points)
miny, maxy = min(p[1] for p in points), max(p[1] for p in points)
points = [(p[0] - minx, maxy - p[1]) for p in points]
grid = [['.'] * (maxx-minx+1) for _ in range(maxy-miny+1)]
for x, y in points:
grid[y][x] = '*'
answer = [''.join(row) for row in grid]
return answer
프로그래머스 코딩테스트 연습 https://school.programmers.co.kr/learn/challenges