1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| from itertools import permutations
def solution(baseball): baseball_list = list(permutations([1,2,3,4,5,6,7,8,9], 3)) answer = []
for i in range(len(baseball_list)): answer.append(True)
for i in baseball: number = tuple(map(int, list(str(i[0]))))
for index, baseball in enumerate(baseball_list): ball = 0 strike = 0
if number[0] == baseball[0]: strike += 1 elif number[0] == baseball[1] or number[0] == baseball[2]: ball += 1 if number[1] == baseball[1]: strike += 1 elif number[1] == baseball[0] or number[1] == baseball[2]: ball += 1 if number[2] == baseball[2]: strike += 1 elif number[2] == baseball[0] or number[2] == baseball[1]: ball += 1
if strike != i[1] or ball != i[2]: answer[index] = False
return len(list(filter(lambda x: x, answer)))
|