**0**

# Math Quiz Time

###
#1
Members - Reputation: **925**

Posted 04 September 2012 - 03:27 AM

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

###
#2
Moderators - Reputation: **7779**

Posted 04 September 2012 - 03:45 AM

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 n

^{2}is the sum of the n first odd numbers.

###
#3
Members - Reputation: **925**

Posted 04 September 2012 - 03:55 AM

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

###
#4
Moderators - Reputation: **7779**

Posted 04 September 2012 - 04:11 AM

###
#5
Members - Reputation: **925**

Posted 04 September 2012 - 04:31 AM

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

###
#7
Members - Reputation: **925**

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.

###
#8
Moderators - Reputation: **7779**

Posted 04 September 2012 - 05:44 AM

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.

###
#9
Crossbones+ - Reputation: **8157**

Posted 04 September 2012 - 07:33 AM

Yes, because multiplying numbers with only '9' digits is something I do every dayDo 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.

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*

###
#11
Crossbones+ - Reputation: **3192**

Posted 04 September 2012 - 06:02 PM

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

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

Posted 04 September 2012 - 07:05 PM

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.

- magic number is 6
- 57 - 6 = 51
- 5 + 1 + x = 9 : x = 3
- and you get 513

###
#14
Crossbones+ - Reputation: **3192**

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 2^{x}

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

###
#15
Crossbones+ - Reputation: **8157**

Posted 04 September 2012 - 11:48 PM

Don't you mean 1/x? Coz the d's cancel outperhaps i'm missing sometin, but "d/dx" = x...right?

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*

###
#16
Crossbones+ - Reputation: **3192**

Posted 04 September 2012 - 11:49 PM

it'd be 1*x, since dx is multiplying d*x, and by order of op's it'd expand to: (d/d)*xDon't you mean 1/x? Coz the d's cancel out

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

...maybe....?

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

###
#17
Crossbones+ - Reputation: **8157**

Posted 04 September 2012 - 11:58 PM

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

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*

###
#18
Members - Reputation: **1148**

Posted 05 September 2012 - 01:29 AM

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