찬우의 이것저것 Chanwoo's blog

[프로그래머스 python]숫자야구

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

이게뭔가 어안이 벙벙하다. 나중에 다시 봐야할거같다.

from itertools import permutations
def check_score(question, candidate, s, b):
    strike = 0
    for i in range(len(question)):
        if question[i] == candidate[i]:
            strike += 1
    if s != strike:
        return False
    ball = len(set(question) & set(candidate))-strike
    if b != ball:
        return False
    return True

def solution(baseball):
    lst = list(permutations([1,2,3,4,5,6,7,8,9], 3))
    for i in baseball:
        for item in lst[:]:
            if not check_score([int(i) for i in list(str(i[0]))], item, i[1], i[2]):
                lst.remove(item)
    return len(lst)

https://geonlee.tistory.com/116