# Reverse 5 digit number by multiplying 4

Rakesh Joshi

Ranch Hand

Posts: 218

Garrett Rowe

Ranch Hand

Posts: 1296

Garrett Rowe

Ranch Hand

Posts: 1296

posted 9 years ago

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.

- 0

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.

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

Ryan McGuire

Ranch Hand

Posts: 1048

4

posted 9 years ago

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

- 0

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

Posts: 55

posted 9 years ago

- 0

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

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

Posts: 1026

Don't get me started about those stupid light bulbs. |