The Problem With # - Algorithm problem

free web hosting
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?

Reply

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

Reply


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*

(Maximum characters: 10,000)
You have characters left.


*RANDOM STUFF*





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




The Problem With # - Algorithm problem



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE