Friday, August 3, 2012

Find the smallest number that is made up of each of the digits 1 through 9 exactly once and is divisible by 99.

To determine if a number is divisible by 99 it needs to be divisible by 9 and 11, both of which can be done easily.

Sum of digits is 1+2+3+4+5+6+7+8+9 = 45 which is divisible by 9.


So any permutation of the digits which give a new number shall be divisible by 9.

We need to construct a permutation of 123456789 which is divisible by 11 and it should give the smallest number.

Let sum of digits in odd position be O and sum of the digits in even position be E

O + E = 45

O- E should be odd and multiple of 11

O-E = 33 => E =6 and sum of 4 digits cannot be 6 (it is minimum 10)

O-E = 11 => E = 17

O - E = - 11 => E = 28

O-E = - 33 => E = 39 is not possible as it is maximum 6+7+8+9 = 30

So let us consider 2 cases

E= 17 and E= 28

E= 17 consider 1st

It can be seen as sum of 4 numbers (< 10 that is digits) and one can be even and 3 odd. Or 3 even and 1 odd.

If the digit is even then this does not get swapped with a digit in odd position and if is odd then it gets swapped. So to keep the number as small as possible the odd digit should be highest and even digits lowest hence one odd digit

So we get the 4 digits 17= 2 + 4 + 6 + 5 => this shall cause odd digit 5 to be swapped with 8

(If we chose 2 + 4 + 3 + 8 then digit 3 gets swapped with 6 and we get a larger number)

So even position digits 2,4,5,6 (sort it to get lower number)

Odd position digits 1,3,7,8,9

And hence number 123475869

If we consider 28 the digits shall be (4789) and 2 goes to odd position and and we get a larger number compared to 123475869 as a larger digit comes there

So solution is number 123475869

This question I picked from http://trickofmind.com/?p=154#comments where you can find some discussions



No comments: