DevYoon

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์นดํŽซ (Python) ๋ณธ๋ฌธ

PS/Programmers

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์นดํŽซ (Python)

gimewn 2022. 4. 21. 00:26

link ๐Ÿ”— https://programmers.co.kr/learn/courses/30/lessons/42842

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์นดํŽซ

Leo๋Š” ์นดํŽซ์„ ์‚ฌ๋Ÿฌ ๊ฐ”๋‹ค๊ฐ€ ์•„๋ž˜ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ์ค‘์•™์—๋Š” ๋…ธ๋ž€์ƒ‰์œผ๋กœ ์น ํ•ด์ ธ ์žˆ๊ณ  ํ…Œ๋‘๋ฆฌ 1์ค„์€ ๊ฐˆ์ƒ‰์œผ๋กœ ์น ํ•ด์ ธ ์žˆ๋Š” ๊ฒฉ์ž ๋ชจ์–‘ ์นดํŽซ์„ ๋ดค์Šต๋‹ˆ๋‹ค. Leo๋Š” ์ง‘์œผ๋กœ ๋Œ์•„์™€์„œ ์•„๊นŒ ๋ณธ ์นดํŽซ์˜ ๋…ธ๋ž€์ƒ‰๊ณผ

programmers.co.kr

 

1๏ธโƒฃ yellow์˜ ์•ฝ์ˆ˜๋ฅผ ๊ตฌํ•ด divisor์— ๋‹ด์•„ ์ฃผ์—ˆ๋‹ค. (yellow์˜ ๋„ˆ๋น„์™€ ๋†’์ด)

2๏ธโƒฃ ์•ฝ์ˆ˜ ๋ฆฌ์ŠคํŠธ์—์„œ ํ•˜๋‚˜์”ฉ ๋ฝ‘์•„ ๋„ˆ๋น„*2+๋†’์ด*2+4๊ฐ€ brown๊ณผ ๊ฐ™์œผ๋ฉด(์•„๋ž˜ ์ด๋ฏธ์ง€ ์ฐธ๊ณ ) answer๋กœ ๋„ˆ๋น„์™€ ๋†’์ด์— ๊ฐ๊ฐ 2์”ฉ ๋”ํ•ด ๋„ฃ์–ด์ฃผ์—ˆ๋‹ค.

 

2a+2b+4 = brown

 

def solution(brown, yellow):
    answer = []
    divisor = []
    for num in range(1, yellow+1):
        if yellow%num == 0:
            if num >= yellow//num:
                divisor.append([num, yellow//num])
    for comb in divisor:
        if comb[0]*2+comb[1]*2+4 == brown:
            answer = [comb[0]+2, comb[1]+2]
    return answer