xisto Community

# The Problem With # Algorithm problem

## Recommended Posts

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?

##### Share on other sites

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).

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account