프로그래머스 - 야구게임[42841] 본문
https://programmers.co.kr/learn/courses/30/lessons/42841
코딩테스트 연습 - 숫자 야구
[[123, 1, 1], [356, 1, 0], [327, 2, 0], [489, 0, 1]] 2
programmers.co.kr
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(range(1,10), 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)
baseball = [[123, 1, 1], [356, 1, 0], [327, 2, 0], [489, 0, 1]]
print(solution(baseball))
'Algorithms > BF (Brute-Force)' 카테고리의 다른 글
테트로미노 [14500] with 파이썬 (0) | 2020.06.02 |
---|---|
테트로미로 [14500] with 파이썬 (0) | 2020.06.01 |
프로그래머스 - 카펫[42842] (0) | 2020.05.23 |
프로그래머스 - 소수 찾기 LV2 [42840] with 파이썬 (0) | 2020.05.22 |
Python 모든 조합 구하기 (0) | 2020.05.22 |