Search
Duplicate

교점에 별 만들기

문제 설명 및 제한사항

아이디어 및 해결 방법

코드

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
Python
복사

출처

프로그래머스 코딩테스트 연습 https://school.programmers.co.kr/learn/challenges