Nov 21, 2009

The Problem With # - Algorithm problem

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Programming General > Algorithms (Languageless)

The Problem With # - Algorithm problem

PureHeart
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?

Comment/Reply (w/o sign-up)

pyost
QUOTE
A
A#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.

CODE
value = a
counter = 0

while (value < k)
   value = calculate(value, a)
   counter = counter + 1

if (value == k)
   return counter
else
   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).

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)


See Also,

*SIMILAR VIDEOS*
Searching Video's for problem, algorithm, problem
advertisement



The Problem With # - Algorithm problem

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com