
https://school.programmers.co.kr/learn/courses/30/lessons/120875


def solution(dots):
def is_parallel(a, b, c, d):
return (b[1] - a[1]) * (d[0] - c[0]) == (d[1] - c[1]) * (b[0] - a[0])
# 가능한 선분 쌍 조합
pairs = [
(0, 1, 2, 3),
(0, 2, 1, 3),
(0, 3, 1, 2)
]
for a, b, c, d in pairs:
if is_parallel(dots[a], dots[b], dots[c], dots[d]):
return 1
return 0
pair 배열을 통해 가능한 선분 3 쌍의 조합을 만들고, is_parallel() 함수를 통해 기울기를 비교했다.1, 없으면 0 을 반환했다.def solution(dots):
[[x1, y1], [x2, y2], [x3, y3], [x4, y4]] = dots
answer1 = ((y1 - y2) * (x3 - x4) == (y3 - y4) * (x1 - x2))
answer2 = ((y1 - y3) * (x2 - x4) == (y2 - y4) * (x1 - x3))
answer3 = ((y1 - y4) * (x2 - x3) == (y2 - y3) * (x1 - x4))
return 1 if answer1 or answer2 or answer3 else 0
is_parallel() 함수의 과정을 풀어서 쓴듯한 과정이다.dy / dx (y 변화량 / x 변화량) 이지만, 분모를 처리하는 과정에서 부동소수점이 발생할 수 있으니, 벡터의 외적 결과처럼 곱셈으로 처리할 수 있다.피드백은 언제나 환영입니다 :)