d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Anyone Have Any Idea How To Solve This?
123Next
Add Reply New Topic New Poll
Member
Posts: 18,413
Joined: Sep 18 2005
Gold: 4,827.00
Feb 5 2014 08:11pm


i am completely stuck and i cant figure out what direction to head with this it would be much appreciated if someone would be able to give me a few hints for what direction to head for this ty

edit:

not looking for it to be solved just for a way that i can go about solving it.

This post was edited by Acdc-rocks[tom] on Feb 5 2014 08:11pm
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Feb 5 2014 08:28pm
Total sum of what? A row? Column? The entire nxn table?
Member
Posts: 18,413
Joined: Sep 18 2005
Gold: 4,827.00
Feb 5 2014 08:32pm
Quote (Minkomonster @ Feb 5 2014 10:28pm)
Total sum of what? A row? Column? The entire nxn table?


entire table
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Feb 5 2014 09:03pm
So, the question is how can you represent each cell of the grid?

Given a number n, construct an nxn grid.
Let's say you had 2 variables i and j, such that 1 <= i <= n, and 1 <= j <= n, then (i,j) would be the coordinates of a cell of that nxn grid.

Your job is to represent each cell of the grid in terms of i, j, and n

for instance, if you wanted every cell of this nxn grid to be the sum of the row and the column then

f(i,j) = i + j

What would the function be for the grid described in the picture? Notice on row(i) 1, as the column(j) increases so does the cell's value. almost as if on that row(i) only the column (j) seems to matter. But as the row increases, and the column stays the same, only the row seems to matter.


You said you only wanted guidance, and I don't want to just give you the answer. Let me know if this gets you anywhere.
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Feb 5 2014 09:03pm
well maybe i'm derping it, but every row looks like an arithmetic series

so you could sum a row with:


Then just sum the sums, unless I'm missing something...
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Feb 5 2014 09:10pm
Food for thought. notice that the sum of row_0 is n(n+1)/2
since row_1 is the same as row_0 shifted by 1, its sum is equal to sum(row_0) - 1 (first slot) + (n+1) (last slot) = sum(row_0) + n
row_2 is the same as row_1 shifted by 1, so its sum is equal to sum(row_1) - 2 (first slot) + (n+2) (last slot) = sum(row_1) + n

using this pattern, we know sum(row_i) = sum(row_(i-1)) + n for i > 0

what else do we know? well, there are n rows

so the sum of the first row is sum(row_0) = sum(row_0)* 1 + n*0
the sum of the first 2 rows is sum(row_0) + sum(row_1) = sum(row_0)+ sum(row_0)+ n = sum(row_0)* 2 + n*1
the sum of the first 3 rows is sum(row_0)+ sum(row_1) + sum(row_2) = sum(row_0)+ sum(row_0)+ n + sum(row_1) + n = sum(row_0)* 3 + n*2

so the sum of the first n rows is sum(row_0)*n + n(n-1)

and we already know what sum(row_0) is, so substitute and simplify.

assuming i did my math right

This post was edited by carteblanche on Feb 5 2014 09:12pm
Member
Posts: 18,413
Joined: Sep 18 2005
Gold: 4,827.00
Feb 5 2014 09:11pm
Quote (Minkomonster @ Feb 5 2014 11:03pm)
So, the question is how can you represent each cell of the grid?

Given a number n, construct an nxn grid.
Let's say you had 2 variables i and j, such that 1 <= i <= n, and 1 <= j <= n, then (i,j) would be the coordinates of a cell of that nxn grid.

Your job is to represent each cell of the grid in terms of i, j, and n

for instance, if you wanted every cell of this nxn grid to be the sum of the row and the column then

f(i,j) = i + j

What would the function be for the grid described in the picture? Notice on row(i) 1, as the column(j) increases so does the cell's value. almost as if on that row(i) only the column (j) seems to matter. But as the row increases, and the column stays the same, only the row seems to matter.


You said you only wanted guidance, and I don't want to just give you the answer. Let me know if this gets you anywhere.


I appreciate that you went into depth with this but unfortunately this honestly just confused me Im not sure what you were trying to get at


Quote (Azrad @ Feb 5 2014 11:03pm)
well maybe i'm derping it, but every row looks like an arithmetic series

so you could sum a row with:
http://www.regentsprep.org/Regents/math/algtrig/ATP2/ArithG3.gif

Then just sum the sums, unless I'm missing something...


I'm not exactly sure how to use this formula to plug these values into it sadly..
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Feb 5 2014 09:14pm
oh, and stick to one topic. it's really annoying when someone gives you an answer in one topic and people keep trying to respond in another.

http://forums.d2jsp.org/topic.php?t=70122182&f=257
Member
Posts: 18,413
Joined: Sep 18 2005
Gold: 4,827.00
Feb 5 2014 09:22pm
Quote (carteblanche @ Feb 5 2014 11:10pm)
Food for thought. notice that the sum of row_0 is n(n+1)/2
since row_1 is the same as row_0 shifted by 1, its sum is equal to sum(row_0) - 1 (first slot) + (n+1) (last slot) = sum(row_0) + n
row_2 is the same as row_1 shifted by 1, so its sum is equal to sum(row_1) - 2 (first slot) + (n+2) (last slot) = sum(row_1) + n

using this pattern, we know sum(row_i) = sum(row_(i-1)) + n for i > 0

what else do we know? well, there are n rows

so the sum of the first row is sum(row_0) = sum(row_0)* 1 + n*0
the sum of the first 2 rows is sum(row_0) + sum(row_1) = sum(row_0)+ sum(row_0)+ n = sum(row_0)* 2 + n*1
the sum of the first 3 rows is sum(row_0)+ sum(row_1) + sum(row_2) = sum(row_0)+ sum(row_0)+ n + sum(row_1) + n = sum(row_0)* 3 + n*2

so the sum of the first n rows is sum(row_0)*n + n(n-1)

and we already know what sum(row_0) is, so substitute and simplify.

assuming i did my math right


Sorry about the multiple topics wasn't sure where i would be able to get an answer. But as for what you wrote, I believe that I understand what is going on and I think I will be able to achieve my answer from that. I really appreciate it thanks!
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Feb 5 2014 09:40pm
Quote (carteblanche @ Feb 5 2014 10:10pm)
Food for thought. notice that the sum of row_0 is n(n+1)/2
since row_1 is the same as row_0 shifted by 1, its sum is equal to sum(row_0) - 1 (first slot) + (n+1) (last slot) = sum(row_0) + n
row_2 is the same as row_1 shifted by 1, so its sum is equal to sum(row_1) - 2 (first slot) + (n+2) (last slot) = sum(row_1) + n

using this pattern, we know sum(row_i) = sum(row_(i-1)) + n for i > 0

what else do we know? well, there are n rows

so the sum of the first row is sum(row_0) = sum(row_0)* 1 + n*0
the sum of the first 2 rows is sum(row_0) + sum(row_1) = sum(row_0)+ sum(row_0)+ n = sum(row_0)* 2 + n*1
the sum of the first 3 rows is sum(row_0)+ sum(row_1) + sum(row_2) = sum(row_0)+ sum(row_0)+ n + sum(row_1) + n = sum(row_0)* 3 + n*2

so the sum of the first n rows is sum(row_0)*n + n(n-1)

and we already know what sum(row_0) is, so substitute and simplify.

assuming i did my math right


/facepalm

I just realized in my response I was under the impression he needed every cell evaluated. If all he needs is the sum of the entire grid and the complexity of the algorithm, then you can calculate that with a series based on the row.

The algorithm can be achieved in linear time in that case.
Go Back To Programming & Development Topic List
123Next
Add Reply New Topic New Poll