Given A,K, the definition

A#B = ( Sum of all digits of A * Maximum digit of B )+Minimum digit of B

and following formulas

A

A#A

(A#A)#A

(A#(A#A))#A

Determine and return the minimal number of necessary # to generate K from A or return -1 if there is no possible solution at all.

I am still looking for a solution to this. Any idea?

AA#A

(A#A)#A

(A#(A#A))#A

Each line must have a greater value than the previous one, so we just need to use the formula until the value becomes K, or exceeds it.value = acounter = 0while (value < k) value = calculate(value, a) counter = counter + 1if (value == k) return counterelse return -1

"calculate" whould be the function you use to calculate result of the # operator. This is quite easy to achieve, as you can take out the digits from a number by using "% 10 (mod 10)", which gives you the remainder when dividing by 10 (the last digit).

VIEW DESKTOP VERSION | REGISTER | GET FREE HOSTING |

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved. |