[Programmers] μ«μμΌκ΅¬
Updated:
μ«μμΌκ΅¬
μ«μμΌκ΅¬ λ₯Ό ν΄λ¦νλ©΄ λ°λ‘ μ΄λνλ€.
μ§λ¬Έμ΄ 1κ°μμ 100κ° μ¬μ΄λ‘ μ£Όμ΄μ§λ©΄ μ΄λ λ΅μ΄ λ μ μλ λͺ¨λ μ«μμ κ°μλ₯Ό λ°ννλ©΄ λλ€.
[ [123, 1, 1], [356, 1, 0], [327, 2, 0], [489, 0, 1] ] μ΄ μ£Όμ΄μ§λ€λ©΄ κ°λ₯ν λ΅μ 324, 328 μ΄ λλ€.
ν΄κ²°λ°©λ²μ 123λΆν° 987κΉμ§ λ°λ³΅νλ©΄μ λͺ¨λ μ§λ¬Έμ Strike, Ball κ³Ό λ΅μ΄ κ°μμ§ λΉκ΅νλ©΄ λλ€.
324μ κ²½μ° 123κ³Ό λΉκ΅νμ λ 1S 1B, 356κ³Ό λΉκ΅νμ λ 2S 0B, 327κ³Ό λΉκ΅νμ λ 2S 0B, 489μ λΉκ΅νμ λ 0S 1B κ° λλ€.
λ¬Έμ 쑰건μμ 1 ~ 9 κΉμ§μ μ€λ³΅λμ§ μλ μ«μκ° μ€κΈ° λλ¬Έμ 0μ΄ μκ±°λ μ€λ³΅μ΄ λλ κ²½μ°λ 체ν¬λ₯Ό νμ§ μλλ€.
def solution(baseball):
answer = 0
for check_num in range(123, 988):
check_num = str(check_num)
if '0' in check_num or len(set(list(check_num))) < 3: # μ«μμ 0μ΄ μκ±°λ μ€λ³΅ λ μ«μκ° μμΌλ©΄ λμ΄κ°λ€
continue
answer_check = 0
for cur in baseball:
strike = 0
ball = 0
answer_num = str(cur[0])
for val in check_num:
try:
if check_num.index(val) == answer_num.index(val):
strike += 1
else:
ball += 1
except ValueError:
pass
if cur[1] == strike and cur[2] == ball:
answer_check += 1
else:
pass
if answer_check == len(baseball):
print(check_num)
answer += 1
return answer
Leave a comment