Question
Test Case 1
def solution(N, number):
possible_number = [[], [N]]
if number == N:
return 1
for count in range(2, 9):
temp = set([int(str(N) * count)])
for j in range(1, count // 2 + 1):
for num1 in possible_number[j]:
for num2 in possible_number[count - j]:
temp.update(calculate(num1, num2))
if number in temp:
return count
possible_number.append(list(temp))
return -1
def calculate(num1, num2):
result = set()
result.add(num1 + num2)
result.add(num1 - num2)
result.add(num2 - num1)
result.add(num1 * num2)
if num1 != 0:
result.add(num2 / num1)
if num2 != 0:
result.add(num1 / num2)
return result
Shell
복사
Test Case 2
Shell
복사
Solve
Python
복사
실행시간 : ms