Scribbling

프로그래머스: 카펫 본문

Computer Science/Coding Test

프로그래머스: 카펫

focalpoint 2021. 10. 19. 23:16

x * y = brown + yellow

(x-2) * (y-2) = yellow

--> 모든 정수 조합 완전 탐색

def solution(brown, yellow):
    answer = []
    xy_product = brown + yellow
    candidates = []
    for i in range(1, xy_product//2+1):
        if xy_product % i == 0:
            candidates.append((xy_product//i, i))
    for candidate in candidates:
        if (candidate[0]-2) * (candidate[1]-2) == yellow:
            return candidate