Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2015-06-13 07:09:45

Transcending
Guest

digit sum

If 212 = 4 096, the digit sum would be 4 + 0 + 9 + 6 = 19.
What is the digit sum of 2789?

#2 2015-06-13 08:08:33

Bob
Administrator
Registered: 2010-06-20
Posts: 10,621

Re: digit sum

hi Transcending

Welcome to the forum.

I first read that as two hundred and twelve, but I guess you meant

In which case you want the digit sum of

Have to do some number crunching first.  Back when I've got something.

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#3 2015-06-13 10:30:52

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: digit sum

Hi;


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#4 2015-06-13 13:23:49

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,877

Re: digit sum

Hi Transcending;

For 2^789 I get:

I used Mathematica. I also verified my answer with a combination of BCalc and Excel...just to see how I could use Excel for such a large number, mainly.

I could also have used pencil and paper to evaluate the power and then summed the digits with mental arithmetic, but I declined because I have to go out later this afternoon and I only have about 4 hours to get ready.

Last edited by phrontister (2015-06-13 14:23:50)


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

#5 2015-06-13 20:41:58

Bob
Administrator
Registered: 2010-06-20
Posts: 10,621

Re: digit sum

I was hoping to reduce this to an algorithm.  There's no obvious pattern.  I have managed to construct a 'formula' for calculating the digit sum, but it can only be used if you already know the full set of digits so it doesn't really help much.

Transcending:  Did this arise from a question on a course?  In which case what method was the questioner expecting?  I had hoped to find an analytic way of solving this.

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#6 2015-06-13 23:25:49

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,877

Re: digit sum

Hi Bob;

I have managed to construct a 'formula' for calculating the digit sum, but it can only be used if you already know the full set of digits...

My BCalc/Excel combo has BCalc evaluating the power and Excel doing the digit sum calculation from BCalc's pasted result.

There are several digit sum methods in Excel, including iteration. Iteration has the briefest code (3 cells, with short formulas totalling 35 characters in all; plus BCalc's pasted answer in another cell)...but it's a bit fiddly.

All that is quite clunky compared with M, which does the whole job on its own with only 26 characters of code. But maybe it can be done with less?

Last edited by phrontister (2015-06-13 23:53:48)


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

#7 2015-06-14 00:18:42

zetafunc
Moderator
Registered: 2014-05-21
Posts: 2,436
Website

Re: digit sum

bob bundy wrote:

I was hoping to reduce this to an algorithm.  There's no obvious pattern.  I have managed to construct a 'formula' for calculating the digit sum, but it can only be used if you already know the full set of digits so it doesn't really help much.

Transcending:  Did this arise from a question on a course?  In which case what method was the questioner expecting?  I had hoped to find an analytic way of solving this.

Bob

My best guess is that this is actually a number theory problem, and that the OP meant to write

2^12 = 4096 -> 4 + 0 + 9 + 6 = 19 -> 1 + 9 = 10 -> 1 + 0 = 1

Do this over the non-negative integer powers of 2, and you'll get a 6-periodic cycle, (1, 2, 4, 8, 7, 5). This can be proven.

Last edited by zetafunc (2015-06-14 00:19:47)

Offline

#8 2015-06-14 00:32:07

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: digit sum

Hi zetafunc;

My best guess is that this is actually a number theory problem, and that the OP meant to write

2^12 = 4096 -> 4 + 0 + 9 + 6 = 19 -> 1 + 9 = 10 -> 1 + 0 = 1

That is called the digital root and can be computed easily using mods.

Hi Bob;

It is possible to come up with a formula for the digital sum but not a closed form. I wasted 30 minutes getting it when all I had to do was look it up at Wikipedia.

At the usual EM watering holes there are other formulas.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#9 2015-06-14 08:06:05

Bob
Administrator
Registered: 2010-06-20
Posts: 10,621

Re: digit sum

hi bobbym,

That looks like my Excel function:

=A1-(INT(A1/1000000) + INT(A1/100000) + INT(A1/10000)+INT(A1/1000)+INT(A1/100)  +INT(A1/10))*9

Cell A1 contains the power of 2 and the various INTs strip off the digits above the units digit to 'count' how many carries have occurred so that an appropriate number of 9s can be subtracted.

Simple example to explain my logic:

2^4 = 16.  If we didn't count in base ten, but rather had a single word and symbol for every number then if 2^4 = hex (say) then the sum of the digits would be hex too.

As we count in base ten, hex = 10.  Every time we cycle the units back to zero and increase the 'tens' by 1 we subtract 10 units and add 1 ten so the digit total goes down by 9.  Thus the digit total for hex = hex - 9 = 7.

For larger numbers, you have to count the carries into the hundreds column, then the thousands and so on.  My formula above is correct up to 7 digit numbers.

Your formula 'counts' how many digits are in the number by the use of logs.

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#10 2015-06-14 09:41:41

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: digit sum

Hi;

That looks good to me.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#11 2015-06-15 04:47:48

Transcending
Member
Registered: 2015-06-15
Posts: 12

Re: digit sum

Thank you so much.

bob bundy,

The question arose from a graduate management test.

These are the answer choices given:
A. 1 880
B. 1 043
C. 1 309
I do not have the official answer.

Offline

#12 2015-06-15 14:28:57

Transcending
Member
Registered: 2015-06-15
Posts: 12

Re: digit sum

Thank you so much guys.
Could someone please teach me how to do this the hard way? i.e. pen & paper?
A book recommendation or any other online source will also be appreciated.

Offline

#13 2015-06-15 16:19:40

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: digit sum

Hi;

Not every problem that looks like a math problem is. Even if there is some arcane method to do this by pencil and paper that comment still holds. This one is much easier to program, so learn to program.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#14 2015-06-15 20:28:16

Transcending
Member
Registered: 2015-06-15
Posts: 12

Re: digit sum

Yes am actually learning python currently. Thank you for your time bobbym.

Offline

#15 2015-06-16 01:48:27

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: digit sum

That is good.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

Board footer

Powered by FluxBB