• Create Account

# Math Quiz Time

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

17 replies to this topic

### #1AltarofScience  Members   -  Reputation: 920

Posted 04 September 2012 - 03:27 AM

I was bored and I'm a bit of an arithmetic nerd, so I figured I would make this thread. I'll ask a question about some math trick and you guys can try to answer it and/or post your own. Getting answers with Google is cheating.

What is the fastest way to calculate the square, in order, of the numbers from 1 to 50?

### #2Brother Bob  Moderators   -  Reputation: 7740

Posted 04 September 2012 - 03:45 AM

It would depend on platform I suppose. For exmple, on the DSP platforms I use quite often, you have hardware loops, one-cycle instructions and parallel compute-and-move instructions, so you can set up the loop, the necessary registers and calculate all squares in 53 cycles using a single computational unit, or 29 cycles using two computational units, and store the results in a memory buffer just using normal multiplication of the loop index with itself.

But, I suspect that is not what you actually intended with your question, but that you were looking for is some mathematical trick to compute the square of a number using as few simple mathematical constructs as possible (with addition being simpler than multiplication for example).
for(int n=1, delta=3, square=1; n<=51; square+=delta, n+=1, delta+=2) {
std::cout << n << " squared is " << square << std::endl;
}

Takes advantage of the fact that n2 is the sum of the n first odd numbers.

### #3AltarofScience  Members   -  Reputation: 920

Posted 04 September 2012 - 03:55 AM

I actually was talking about humans doing it, and not computers. But you gave the correct answer.

I would have phrased it in words as:

Add the next odd number to the current value.

Add 1 to 0 to get 1 is the square of 1. Add 3 to 1 to get 4 is the square of 2. Add 5 to 4 to get 9 is the square of 3.

I should have known someone would give me code

After writing that, I realized you gave me an English version under the code, but I didn't notice since the phrasing is not suitably colloquial for my brain.

Next quiz:

How would a human calculate, in their head, the product of two numbers containing an arbitrary number of digits, where all the digits are 9?

An example would be 9999999999 x 99999999 of which the result is 999999989900000001.

Edited by AltarofScience, 04 September 2012 - 03:59 AM.

### #4Brother Bob  Moderators   -  Reputation: 7740

Posted 04 September 2012 - 04:11 AM

I take an example using a determined number of 9s to show the steps: 9999*99 = (10000-1)*(100-1) = 10000*100-10000-100+1. Multiplication by 10-exponents is trivial by counting zeros, two trivial subtractions by 1-non-zero-digit numbers (and do the subtraction with the smallest one to not even have to care about borrowing during subtraction), followed by another trivial addition by 1.

### #5AltarofScience  Members   -  Reputation: 920

Posted 04 September 2012 - 04:31 AM

Its true that that is a good method and probably the traditional one they teach in school but, its not optimal.

Look at this example:

9*9=81
99*99=9801
999*999=998001
9999*9999=99980001

99*9=891
999*99=98901
9999*999=9989001
99999*9999=99989001

999*9=8991
9999*99=989901
99999*999=99899001
999999*9999=9998990001

9999*9=89991
99999*99=9899901
999999*999=998999001
9999999*9999=9998999001

Edited by AltarofScience, 04 September 2012 - 04:33 AM.

### #6Brother Bob  Moderators   -  Reputation: 7740

Posted 04 September 2012 - 04:53 AM

I know the pattern, but in my opinion it is more difficult to remember the pattern and replicate the result from a given number of nines than to just use some trivial and universal mathematical tools.

### #7AltarofScience  Members   -  Reputation: 920

Posted 04 September 2012 - 05:01 AM

I know the pattern, but in my opinion it is more difficult to remember the pattern and replicate the result from a given number of nines than to just use some trivial and universal mathematical tools.

Do you think that knowing the pattern is faster if you are able to keep track of it? For instance a more general system may be slower, but it can be applied across a wide range of problems, whereas with patterns you have to know the pattern for each specific problem type. Plus general patterns will see more use, this solidifying them in memory.

### #8Brother Bob  Moderators   -  Reputation: 7740

Posted 04 September 2012 - 05:44 AM

I think the fact that you have to remember a pattern is worse than applying trivial and universal mathematical tools. The key points here are universal because I don't have to remember anything specific to multiplying numbers of nines, and trivial because it only involves a very simple multiplication of powers of 10 and three equally trivial subtractions/additions. You have to remember different patterns if the problem changes the problem slightly so that one or both series of nines ends with, say, an eight instead, but I can apply my very same trivial and universal tools, and end up with the very same trivial multiplications and subtractions.

Now, if the resulting calculations from my method involves non-trivial multiplications or subtractions, then we can discuss the benefit of patterns and I could agree. But, in my opinion, the triviality of the operations involved simply doesn't justify remembering specific patterns in this case.

### #9Bacterius  Crossbones+   -  Reputation: 7964

Posted 04 September 2012 - 07:33 AM

Do you think that knowing the pattern is faster if you are able to keep track of it? For instance a more general system may be slower, but it can be applied across a wide range of problems, whereas with patterns you have to know the pattern for each specific problem type. Plus general patterns will see more use, this solidifying them in memory.

Yes, because multiplying numbers with only '9' digits is something I do every day

I would agree that some patterns are useful to remember, such as or instead of working through them each time using algebra, since after a while you can recognize them instantly and they come up often, but in this case, what makes the '9' pattern any more special than the '1' or '2' or '5' pattern? And the pattern doesn't come up that often - I don't feel it's worth remembering this one.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

- Pessimal Algorithms and Simplexity Analysis

### #10jfavela  Members   -  Reputation: 143

Posted 04 September 2012 - 05:53 PM

### #11slicer4ever  Crossbones+   -  Reputation: 3074

Posted 04 September 2012 - 06:02 PM

i believe these questions are going to only resu

Its true that that is a good method and probably the traditional one they teach in school but, its not optimal.

you only asked for a solution, not an optimal solution, I believe BB's solution is equally on par with yours(if not better imo).

I was expecting your questions to be a bit different then what you posted, as these arn't really math "tricks" as much as math tips.

also, for your first question, in high school I became very obsessed with discovering that formula, I was always trying to figure out another way to devise the square of a number instead of multiplying the number, too which i eventually figured out the formula of n^2 =(n-1)^2+( (n-1)^2-(n-2)^2+2); or counting a delta upwards by 2 to be added to each squared number to reach the next.

Edited by slicer4ever, 04 September 2012 - 06:15 PM.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

### #12hupsilardee  Members   -  Reputation: 486

Posted 04 September 2012 - 06:50 PM

my turn
This is one i use to catch out 18-21 year old maths students, so lets see how gamedev does.

Evaluate d/dx of 2x

### #13tstrimple  Prime Members   -  Reputation: 1718

Posted 04 September 2012 - 07:05 PM

I love math. I've got a trick for multiplying by 9 which does probably come up more often than by 999999

First round up to the nearest 10s place and then divide by 10 to get the magic number.
0 - 10 rounds up to 10, becomes 1,
11 - 20 rounds up to 20, becomes 2,
21 - 30 rounds up to 30, becomes 3, etc...

Subtract the magic number from the original number and then add a digit onto the end which will make all of the resulting digits add up to 9. Some examples.

9 * 13
• magic number is 2
• 13 - 2 = 11
• 1 + 1 + x = 9 : x = 7
• And the answer is 117.
9 * 57
• magic number is 6
• 57 - 6 = 51
• 5 + 1 + x = 9 : x = 3
• and you get 513

### #14slicer4ever  Crossbones+   -  Reputation: 3074

Posted 04 September 2012 - 11:42 PM

my turn
This is one i use to catch out 18-21 year old maths students, so lets see how gamedev does.

Evaluate d/dx of 2x

perhaps i'm missing sometin, but "d/dx" = x...right?
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

### #15Bacterius  Crossbones+   -  Reputation: 7964

Posted 04 September 2012 - 11:48 PM

perhaps i'm missing sometin, but "d/dx" = x...right?

Don't you mean 1/x? Coz the d's cancel out

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

- Pessimal Algorithms and Simplexity Analysis

### #16slicer4ever  Crossbones+   -  Reputation: 3074

Posted 04 September 2012 - 11:49 PM

perhaps i'm missing sometin, but "d/dx" = x...right?

Don't you mean 1/x? Coz the d's cancel out

it'd be 1*x, since dx is multiplying d*x, and by order of op's it'd expand to: (d/d)*x

...maybe....?

Edited by slicer4ever, 04 September 2012 - 11:53 PM.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

### #17Bacterius  Crossbones+   -  Reputation: 7964

Posted 04 September 2012 - 11:58 PM

it's be 1*x, since dx is multiplying d*x, and by order of op's it'd expand to: (d/d)*x

...maybe....?

Oh you would be right. But then what purpose does 2^x serve? Perhaps we need to multiply it.... my answer is x * 2^x.

And that's 3^x since there's one more x. I think, anyway - my math is a bit rusty!

Although seriously, while the answer to d/dx 2^x is fairly straightforward if you know the formula for differentiating exponentials, it is interesting to derive it yourself.

Edited by Bacterius, 05 September 2012 - 12:04 AM.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

- Pessimal Algorithms and Simplexity Analysis

### #18RulerOfNothing  Members   -  Reputation: 1142

Posted 05 September 2012 - 01:29 AM

I am going to assume d/dx means "take the derivative with respect to x". In that case it is log2*2^x. This is because 2^x is equal to e^(x*log2) (where log is the natural logarithm i.e. in base e) so since the derivative of e^ax with respect to x is a*e^ax, we get log2*e^(x*log2) which is equal to the result given above.
With the squares, you can exploit the fact that the difference between n^2 and (n+1)^2 is 2n+1 (using the difference of two squares formula), so you can use addition to get the squares of the first 50 counting numbers.

Edited by RulerOfNothing, 05 September 2012 - 01:43 AM.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS