프로그래머스 완전탐색 카펫 파이썬 풀이

minan·2021년 6월 20일
0

프로그래머스

목록 보기
6/92

프로그래머스 완전탐색 Level 2 카펫 파이썬 풀이

https://programmers.co.kr/learn/courses/30/lessons/42842

가로가 세로보다 크다.
전체 크기를 가로만큼 나누고 나누어떨어진다면 그 안에 노란카펫이 들어갈 수 있는지 확인하면 되는 문제

def solution(brown, yellow):
    answer = []
    
    sum_brown_yellow = brown + yellow # 전체 크기
    
    # 가로 길이
    for width in range(sum_brown_yellow, 0, -1):
        height = sum_brown_yellow % width # 전체크기 % 가로길이의 
        if height == 0: # 나누어 떨어진다면
            # 안에 노란색 카펫이 들어갈 수 있는지 확인
            if yellow == (sum_brown_yellow/width-2)*(width-2): 
                return [width, sum_brown_yellow/width]
profile
https://github.com/minhaaan

0개의 댓글