chyam

[프로그래머스 Lv2, python] - 비밀 코드 해독 본문

프로그래머스/LV2

[프로그래머스 Lv2, python] - 비밀 코드 해독

chyam_eun 2025. 6. 25. 13:40

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

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

from itertools import combinations

def solution(n, q, ans):
    answer = 0
    arr = []
    for i in range(1,n+1):
        arr.append(str(i))
    # 1~n까지 숫자로 가능한 5개의 조합? 
    li = list(combinations(arr,5))
    q_len = len(q)
    
    # li를 정답으로 치고, q를 하나씩 돌면서  ans의 결과와 같으면 +1, 하나라도 다르면 break
    for correct in li:
        iscorrect = True
        for i in range(len(ans)):
            tmp = 0
            for j in range(5):
                if str(q[i][j]) in correct:
                    tmp += 1
            if tmp != ans[i]:
                iscorrect = False
                break
        if iscorrect == True:        
            answer += 1

    return answer