+ 2

Hello everyone if anyone can help me break down this problem C++

Hello, I was wondering If I can get some help or some advice on how to program this functin so assume that I made a 4 by 4 array example : int a[4][4] = { { 1,4,5,6 }, { 2,12,11,3 }, { 8,16,23,32 }, {9,14,20,21} }; Assume that the value starts at [0][1] to [1][0] to [2][1] to [3][2] to [2][3] to [1][2] then to [0][1] the pattern is that each value is not going outside of their boundary and for the function, I want to add them all up so how can I start programming this.

29th Apr 2021, 7:36 PM
boba
boba - avatar
24 Answers
+ 2
This will help you for handling with 2D arrays. For more information please link here your attempt: https://code.sololearn.com/chi7HM5s0V90/?ref=app
29th Apr 2021, 8:21 PM
JaScript
JaScript - avatar
+ 2
Think of a ping pong bouncing off starting from its origin point and bouncing off when it touches a wall then goes all the way to its origin, if you make a 4 by 4 and follow what the columns and rows youll see that it will form a parallel
30th Apr 2021, 1:53 AM
boba
boba - avatar
+ 2
Okay, anyways thanks for help when you have the time you can explain it to me how to set it up as a for loo0
30th Apr 2021, 2:51 AM
boba
boba - avatar
+ 2
. 0,1 1,0. 1,2 2,1 2,3 3,2 you can keep xstart=0, ystart=1 as initial coordinates, and then you can move in 4 directions sequentially and stop when starting coordinate is reached. To make it more simple you can make 4 loops one after other for each direction in same sequence like first going down-left then right-down then up-right etc, and break from each loop when same coordinate is reached or can't make a move. Atmax 4 loops only because if you'll try with some NxN boards then it will reach same coordinate after 4 loops.
30th Apr 2021, 3:14 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 2
boba yes you can that. Please se my updated code, how it can be done: https://code.sololearn.com/chi7HM5s0V90/?ref=app
30th Apr 2021, 10:54 AM
JaScript
JaScript - avatar
+ 2
Hey, I've written a function that traverses your 2d array with "bouncing on the walls" for a given first and second point. You can customize it for your own problem. https://code.sololearn.com/c20BK8vTVl72/?ref=app
1st May 2021, 4:18 PM
Balázs Szabó
Balázs Szabó - avatar
+ 2
boba only for an example to learn, now you can build your own patterns.
2nd May 2021, 10:54 AM
JaScript
JaScript - avatar
+ 1
JaScript like I want to start at 2 at the first column to 4 in the second column to 11 in the third to 32 in the fourth to 20 back to the third to 16 in the second and back to 2 in then first
29th Apr 2021, 8:33 PM
boba
boba - avatar
+ 1
So technically theres a 4 by 4 array and i have a total of 6 values in this 4 by 4 one starting off as its first destination at [0] [1] then it adds another value to [1][0] then it adds to [2][1] then to [3][2] to [2][3] to [1][2] to [0][1] stops at [0][1] like its travelling
30th Apr 2021, 1:50 AM
boba
boba - avatar
+ 1
Is it possible to do that off of a for loop? Martin Taylor
30th Apr 2021, 2:44 AM
boba
boba - avatar
+ 1
Think of a ping pong bouncing off starting from its origin point and bouncing off when it touches a wall then goes all the way to its origin, if you make a 4 by 4 and follow what the columns and rows youll see that it will form a parallel
1st May 2021, 3:47 PM
Kishore
+ 1
boba yes you can that. Please se my updated code, how it can be done: https://code.sololearn.com/chi7HM5s0V90/?ref=app
1st May 2021, 3:48 PM
Kishore
+ 1
Good job JaScript
1st May 2021, 3:48 PM
Kishore
+ 1
4 3?
1st May 2021, 5:49 PM
boba
boba - avatar
0
Michał Doruch will you help.me.ouy
29th Apr 2021, 9:26 PM
boba
boba - avatar
0
Martin Taylor any advice on how to do this, more like a traversal array problem I guess you can say
30th Apr 2021, 1:29 AM
boba
boba - avatar
0
[Columns][Rows]
30th Apr 2021, 1:51 AM
boba
boba - avatar
0
Why is it 4 3
1st May 2021, 8:05 PM
boba
boba - avatar
0
??
3rd May 2021, 7:39 PM
boba
boba - avatar