Showing posts with label Sum of Digits. Show all posts
Showing posts with label Sum of Digits. Show all posts

Sunday, 25 December 2016

Solution to "Sum of Digits"

View Problem: Sum of Digits

The value of the number abc is equal to 100*a + 10*b + c. Similarly, the value of def is equal to 100*d + 10*e + f. Adding these two gives us 100*(a+d) + 10*(b+e) + (c+f), which is the value of ghij. Let us try to represent g, h, i and j in terms of a, b, c, d, e and f:

Case 1: (a+d) < 10, (b+e) < 10, (c+f) < 10

For this case,

  • g = 0
  • h = a+d
  • i = b+e
  • j = c+f

So, g + h + i + j = a + b + c + d + e + f. Hence (a + b + c + d + e + f) % 9 = (g + h + i + j)%9

Case 2: (a+d) >= 10, (b+e) < 10, (c+f) < 10

For this case,

  • g = 1
  • h = (a+d)%10
  • i = b+e
  • j = c+f

If we prove that (a + b + c + d + e + f - (g + h + i + j)) % 9 = 0, we are done.
  (a + b + c + d + e + f - (g + h + i + j)) % 9 
= (a + b + c + d + e + f - (1 + (a+d)%10 + b+e + c+f)) % 9
= (a + d - 1 - (a+d)%10) % 9
= (10-1) % 9 //(a+d)-(a+d)%10 = 10 as a, d lie in [0..9] so (a+d) lies in [0..18]
= 9 % 9
= 0
Hence proved for this case.

Similarly, the proof can be continued for all cases, and generalized as well.

Monday, 19 December 2016

Sum of Digits

Say we have 2 numbers abc and def, where, a, b, c, d, e and f are the digits of the 2 numbers lying in [0..9]. Adding these 2 numbers gives us the number ghij. Again, g, h, i and j are the digits of the resulting number.
  abc
+ def
----------
 ghij
Can you prove that

(a + b + c + d + e + f) % 9 = (g + h + i + j) % 9 

is always true?

To understand better, let us see an example -
  379
+ 822
----------
 1201

(3 + 7 + 9 + 8 + 2 + 2) % 9 = 31 % 9 = 4
(1 + 2 + 0 + 1) % 9 = 4 % 9 = 4

Let us now generalize the above statement. Say we have N numbers A1, A2, ... AN. Let S(x) denote the sum of digits of the the number x.

Can you prove that

[S(A1) + S(A2) + .. + S(AN)] % 9 = S(A1 + A2 + .. + AN) % 9

is always true?

To put it in a single sentence, can you prove that the sum of digits of a group of numbers modulo 9 is the same as the sum of digits of the sum of those numbers modulo 9 ?