from itertools import permutations
def solution(baseball):
answer = 0
correct=list(permutations([1,2,3,4,5,6,7,8,9], 3))
for i in range(len(baseball)):
tmp=tuple(map(int,list(str(baseball[i][0]))))
#print("tmp:",tmp)
cr_num=0
try:
while correct!=[]:
st_chk=0
b_chk=0
#check strike and ball
if tmp[0]==correct[cr_num][0]:
st_chk+=1
elif tmp[0]==correct[cr_num][1]:
b_chk+=1
elif tmp[0]==correct[cr_num][2]:
b_chk+=1
if tmp[1]==correct[cr_num][1]:
st_chk+=1
elif tmp[1]==correct[cr_num][0]:
b_chk+=1
elif tmp[1]==correct[cr_num][2]:
b_chk+=1
if tmp[2]==correct[cr_num][2]:
st_chk+=1
elif tmp[2]==correct[cr_num][0]:
b_chk+=1
elif tmp[2]==correct[cr_num][1]:
b_chk+=1
if st_chk!=baseball[i][1]:
del correct[cr_num]
elif b_chk!= baseball[i][2]:
del correct[cr_num]
elif cr_num!=len(correct)-1:
cr_num+=1
else:
break
except:
pass
answer=len(correct)
return answer
'STUDY > Algorithm' 카테고리의 다른 글
[프로그래머스] LEVEL2 멀쩡한 사각형,python3, 서머코딩/윈터코딩(2019) (0) | 2019.11.19 |
---|---|
[프로그래머스] LEVEL2 위장, python3, 해시 (0) | 2019.11.18 |
[프로그래머스] LEVEL2 구명보트, python3, 탐욕법(greedy) (0) | 2019.11.14 |
[프로그래머스] LEVEL2 H-Index, python3, 정렬 (0) | 2019.11.14 |
[프로그래머스] LEVEL2 전화번호목록,python3, 해시 (0) | 2019.11.13 |