My solution:
def calculate(int_coin_price):
possible_price_splitted = (int_coin_price//2) + (int_coin_price//3) + (int_coin_price//4)
final_result = possible_price_splitted if possible_price_splitted>int_coin_price else int_coin_price
return final_result
while True:
try:
coin_price = int(input())
print(calculate(coin_price))
except EOFError:
break
A similar solution I found:
dict1 = {0:0}
def calculate(coinprice):
if coinprice in dict1:
return dict1[coinprice]
else:
value = calculate(coinprice//2) +calculate(coinprice//3) +calculate(coinprice//4)
if value > coinprice:
dict1[coinprice] = value
return value
else:
dict1[coinprice] = coinprice
return dict1[coinprice]
while True:
try:
coin_price = int(input())
print(calculate(coin_price))
except EOFError:
break
this one is correct and I don’t understand the difference. I can see there is a dictionary but don’t know if this difference is the one that makes it accepted.