Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> The Problem With #, Algorithm problem
PureHeart
post Mar 19 2008, 02:29 AM
Post #1


Premium Member
Group Icon

Group: Members
Posts: 209
Joined: 7-October 05
From: Đà Nẵng City - Việt Nam
Member No.: 8,966



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?
Go to the top of the page
 
+Quote Post
pyost
post Mar 19 2008, 02:21 PM
Post #2


Nenad Bozidarevic
Group Icon

Group: [MODERATOR]
Posts: 1,002
Joined: 7-November 05
From: Belgrade, Serbia
Member No.: 9,500



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).
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Collision Check Algorithm(2)


 



- Lo-Fi Version Time is now: 7th September 2008 - 07:04 PM