aspose file tools*
The moose likes Programming Diversions and the fly likes Reverse 5 digit number by multiplying 4 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Reverse 5 digit number by multiplying 4" Watch "Reverse 5 digit number by multiplying 4" New topic
Author

Reverse 5 digit number by multiplying 4

Rakesh Joshi
Ranch Hand

Joined: Feb 24, 2006
Posts: 218
A, B, C, D and E are 5 different single digit numbers. The number ABCDE times 4 will have a result of EDCBA. What digit numbers do A, B, C, D, and E represent?

ABCDE
* 4
-------
EDCBA
-------


Life is a Game play it.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
21978


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Could any one tell me what is the logic to calculate this problem. Atleast direct others how to calculate this problem or tell the algorithm to solve it....


The Best way to predict your future is to create it - Every great individual common man
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
Originally posted by Ankur Sharma:
Could any one tell me what is the logic to calculate this problem. Atleast direct others how to calculate this problem or tell the algorithm to solve it....


21978 * 4 = 87912

I just used a simple loop from 10000 to 99999 and multiplied each number by 4, converted to a String, and checked to see if the String reversed was equal to the original number as a String.
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 988
    
    1
Originally posted by Ankur Sharma:
Could any one tell me what is the logic to calculate this problem. Atleast direct others how to calculate this problem or tell the algorithm to solve it....


You could look at it as an integer linear programming problem.

Find A,B,C,D,E such that.

A*10000 + B*1000 + C*100 + D*10 + E = 4*(E*10000 + D*1000 + C*100 + B*10 + A)
- or -
A*9996 + B*960 - C*300 - D*3990 - E*39999 = 0
A >= 0
A <= 9
B >= 0
B <= 9
C >= 0
C <= 9
D >= 0
D <= 9
E >= 0
E <= 9
fred Joly
Ranch Hand

Joined: Jan 19, 2006
Posts: 55
- A can only be 1 or 2
if A > 2 then the answer would be of the form FEDCBA


-let's try with A = 1
1BCDE
*4
------
EDCB1

impossible : 4*E = some number ending by 1

- then A "MUST" be 2
2BCDE
*4
-----
EDCB2


- E=3 or E=8 (E*4 has to be a number ending with 2)

let's try E=8 (looks like the easier...)

2BCD8
*4
-----
8DCB2


- B can only 1 or 2 (otherwise 4*B > 10 and that's now impossible)
Since we already have a 2 , b=1

21CD8
*4
-----
8DC12


- we can write : D*4 + 3 = some number ending by 1
->D*4 = some number ending by 8

D=2 or D=7 => D=7 (A = already 2)


21C78
*4
-----
87C12


- (4*21000 = 84000)
we can write

C78
*4
-----
3C12

we can write C*4 + 3 = 3C (beware 3C means thirty C)
so C >= 7
we already have a 7 and a 8 => C = 9

21978
*4
-----
87912


No computer needed to do this...
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

A great performance-improvement would be to reduce the loop to unique digits in the numbers:


http://home.arcor.de/hirnstrom/bewerbung
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reverse 5 digit number by multiplying 4
 
Similar Threads
please review- NumberFormatException in Conversation of String to Hexadecimal
Chapter 6 Self Test Q1
what's wrong with this code?
how to create a boolean truth table
Take the Dr. Phil Test