# Simple math question

## Recommended Posts

Its been a while since i were in school, and i werent that good at math even in school to start with . I ran into a problem calculating the following...

For example: 1x1 + 2x1 + 3x1 + 4x1 + 5x1 = 15

The thing is i just dont remember how to do this math. Im pretty sure it involved something like this (x * y) and something else hehe.

```\$x = 10
\$y = 2

\$sum = <some formula here>```

Hope someone knows how it worked!

Edited by huldu

"I'm paper, rock is fine, nerf scissors!!!"

##### Share on other sites

```\$x = 10
\$y = 2

\$sum = \$x*\$y
MsgBox(0,"Total",\$sum)```

This seems too easy so I have probably misunderstood what you are asking

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

##### Share on other sites

It doesnt give the result however.

This is how the math looks before the "forumla": 1x1 + 1x2 + 1x3 + 1x4 + 1x5 = 15

The formula made the above math much more simple as you only needed to insert x and y to get the sum.

"I'm paper, rock is fine, nerf scissors!!!"

##### Share on other sites

It doesnt give the result however.

This is how the math looks before the "forumla": 1x1 + 1x2 + 1x3 + 1x4 + 1x5 = 15

The formula made the above math much more simple as you only needed to insert x and y to get the sum.

Try

```\$sum = (1*1)+(1*2)+(1*3)+(1*4)+(1*5)
MsgBox(0,"Total",\$sum)```

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

##### Share on other sites

Ye hehe i understand that Lets say the user adds a number x and wants it added with y (like below). How would the formula look?

\$sum = (1*1)+(1*2)+(1*3)+(1*4)+(1*5)

Since x is always the same, thats the easy part. However y is changing as you add up.

\$x = 1

\$y = 5

\$sum = (\$x * \$y)^2 / 2 .. ugh (just cant get it to work)

When this "caluclation" is complete the total should be 15, thats all i know Edited by huldu

"I'm paper, rock is fine, nerf scissors!!!"

##### Share on other sites

This any good to you?

```\$x = 1
\$y = 5
\$Sum = 0

For \$i = 1 To \$y
\$Sum = \$Sum + (\$x * \$i)
Next

MsgBox(0,'Sum',\$Sum)```
----[ SandyD ]---
##### Share on other sites

Ye this seems right, thanks

"I'm paper, rock is fine, nerf scissors!!!"

##### Share on other sites

```\$x = 1
\$y = 5

\$sum = (\$x * \$y)^2 / 2
MsgBox(0,"", \$sum)```

this is correct

1 x 5 = 5

5 Squared = 25

25 divided by 2 = 12.5 ( not 15 as you were looking for)

and the message box reflects the correct answer of 12.5

8) ##### Share on other sites

```\$x = 1
\$y = 5

\$sum = (\$x * \$y)^2 / 2
MsgBox(0,"", \$sum)```

this is correct

1 x 5 = 5

5 Squared = 25

25 divided by 2 = 12.5 ( not 15 as you were looking for)

and the message box reflects the correct answer of 12.5

8)

it's triangular numbers guys... Nth triangular number = N + (N-1) + (N-2) + (N-3) ...

when i was playing with recursion i made a little script for figuring triangular numbers recursively...

```HotKeySet("{CAPSLOCK}","endit")
Func endit()
Exit
EndFunc
while 1
\$blah = Number(InputBox("Enter a number","Enter a number N to find the Nth triangular number",6))
MsgBox(0,"triangular numbers",triangle(\$blah))
WEnd
func triangle(\$blah)
if \$blah = 1 Then
Return(1)
Else
Return(\$blah + triangle(\$blah-1))
EndIf
EndFunc```
##### Share on other sites

Although you may have to use Mathematical Induction to prove this is the answer it it is not necessary to use recursion to calculate 1 + 2 + ... + N. The answer is N * (N + 1 ) / 2. The solution to the problem

x*1 + x * 2 + ... + x * y

y a positive integer, is x * y * (y + 1) / 2.

##### Share on other sites

Although you may have to use Mathematical Induction to prove this is the answer it it is not necessary to use recursion to calculate 1 + 2 + ... + N. The answer is N * (N + 1 ) / 2. The solution to the problem

x*1 + x * 2 + ... + x * y

y a positive integer, is x * y * (y + 1) / 2.

HI,

yeah that is although what I can remember from school

```\$x = 1
\$y = 5
MsgBox(0, "", \$x * \$y * (\$y + 1) / 2)```

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

##### Share on other sites

Although you may have to use Mathematical Induction to prove this is the answer it it is not necessary to use recursion to calculate 1 + 2 + ... + N. The answer is N * (N + 1 ) / 2. The solution to the problem

x*1 + x * 2 + ... + x * y

y a positive integer, is x * y * (y + 1) / 2.

i didn't mean to imply that i thought recursion was the only way to go; i was on a little bit of a recursion kick for a little while last month or the month before, and that was just one implementation of it.

##### Share on other sites

"Simple math question"

not so simple!!!

lol

8) ##### Share on other sites

"Simple math question"

not so simple!!!

You're right, but it takes me back (retired math lecturer). This problem is one of the first proofs for which we used Mathematical Induction (which is the backbone of recursion) but I also remember doing this at secondary school before I came across Mathematical Induction and the method is neat, simple when you see it, but not something you would necessarily think of immediately.

Let

S = 1 + 2 + .... + N

turn the order of the terms round, then

S = N + (N-1) + ... + 1

add these two sums up term-by-term

2S = (N + 1) + (N -1 + 2) + .... + (1 + N) = N * (N + 1)

all the brackets are equal to N + 1 and there are N of them, so the right hand side adds up to N * (N + 1). Divide both sides by 2

S = N * (N + 1) / 2

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...