|
|
|
|
![]() ![]() |
Mar 19 2008, 02:29 AM
Post
#1
|
|
|
Premium Member 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? |
|
|
|
Mar 19 2008, 02:21 PM
Post
#2
|
|
|
Nenad Bozidarevic Group: [MODERATOR] Posts: 993 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). |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 6th July 2008 - 10:07 PM |