How to Count Unique squares a robot visits in C# console [closed]
up vote
-6
down vote
favorite
You work for a company that sells robots that move around a factory floor in a grid like pattern. Your boss has asked you to write a program that will test how many unique squares a robot visits given a set of instructions.
For example the input N4,E2,S2,W4 (described below) should result in a value of 11.
The robot starts at position 1, heads north for four blocks, east for two blocks, south for two and west for four. During those steps it visits blocks 1-12 once except for block 2 which it visits twice. Block 2 should only be counted once. The size of the grid is unknown and not given in the input.
I have tried the below but is not getting unique values.I also want a way to get the input in the formart N4,E2,S2,W4 not with separate prompts for direction.
static void Main(string args)
{
int x1 = 0;
int y1 = 0;
int x2 = 0;
int y2 = 0;
int x3 = 0;
int y3 = 0;
int x4 = 0;
int y4 = 0;
int N, S, E, W, Total;
string coordinate1, coordinate2, coordinate3, coordinate4;
Console.Write("Enter North : ");
N = int.Parse(Console.ReadLine());
if(N != 0)
{
x1 += 0;
y1 += N;
}
coordinate1 = "(" + x1 + "," + y1 + ")";
Console.Write("Enter East: ");
E = int.Parse(Console.ReadLine());
if (E != 0)
{
y3 += 0;
x3 += E;
}
coordinate3 = "(" + x3 + "," + y3 + ")";
Console.Write("Enter South: ");
S = int.Parse(Console.ReadLine());
if (S != 0)
{
x2 += 0;
y2 -= S;
}
coordinate2 = "(" + x2 + "," + y2 + ")";
Console.Write("Enter West: ");
W = int.Parse(Console.ReadLine());
if (W != 0)
{
y4 += 0;
x4 -= W;
}
coordinate4 = "(" + x4 + "," + y4 + ")";
if (coordinate1 == coordinate2|| coordinate1== coordinate3 || coordinate1 == coordinate4 || coordinate2 == coordinate3 || coordinate2 == coordinate4 || coordinate3 ==coordinate4 )
{
Total = (N + S + E + W) - 1 ;
Console.WriteLine("The total Blocks travelled are " + Total);
}
else
{
Total = N + S + E + W;
Console.WriteLine("The total Blocks travelled are " + Total);
}
}
c#
closed as too broad by Steve, tripleee, Christian Gollhardt, jww, Tetsuya Yamamoto Nov 12 at 8:22
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
|
show 3 more comments
up vote
-6
down vote
favorite
You work for a company that sells robots that move around a factory floor in a grid like pattern. Your boss has asked you to write a program that will test how many unique squares a robot visits given a set of instructions.
For example the input N4,E2,S2,W4 (described below) should result in a value of 11.
The robot starts at position 1, heads north for four blocks, east for two blocks, south for two and west for four. During those steps it visits blocks 1-12 once except for block 2 which it visits twice. Block 2 should only be counted once. The size of the grid is unknown and not given in the input.
I have tried the below but is not getting unique values.I also want a way to get the input in the formart N4,E2,S2,W4 not with separate prompts for direction.
static void Main(string args)
{
int x1 = 0;
int y1 = 0;
int x2 = 0;
int y2 = 0;
int x3 = 0;
int y3 = 0;
int x4 = 0;
int y4 = 0;
int N, S, E, W, Total;
string coordinate1, coordinate2, coordinate3, coordinate4;
Console.Write("Enter North : ");
N = int.Parse(Console.ReadLine());
if(N != 0)
{
x1 += 0;
y1 += N;
}
coordinate1 = "(" + x1 + "," + y1 + ")";
Console.Write("Enter East: ");
E = int.Parse(Console.ReadLine());
if (E != 0)
{
y3 += 0;
x3 += E;
}
coordinate3 = "(" + x3 + "," + y3 + ")";
Console.Write("Enter South: ");
S = int.Parse(Console.ReadLine());
if (S != 0)
{
x2 += 0;
y2 -= S;
}
coordinate2 = "(" + x2 + "," + y2 + ")";
Console.Write("Enter West: ");
W = int.Parse(Console.ReadLine());
if (W != 0)
{
y4 += 0;
x4 -= W;
}
coordinate4 = "(" + x4 + "," + y4 + ")";
if (coordinate1 == coordinate2|| coordinate1== coordinate3 || coordinate1 == coordinate4 || coordinate2 == coordinate3 || coordinate2 == coordinate4 || coordinate3 ==coordinate4 )
{
Total = (N + S + E + W) - 1 ;
Console.WriteLine("The total Blocks travelled are " + Total);
}
else
{
Total = N + S + E + W;
Console.WriteLine("The total Blocks travelled are " + Total);
}
}
c#
closed as too broad by Steve, tripleee, Christian Gollhardt, jww, Tetsuya Yamamoto Nov 12 at 8:22
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
2
We aren't going to do your homework for you. Have you tried anything yet? Where exactly are you stuck?
– Mureinik
Nov 12 at 7:46
I have added the sample code of what i have tried please help.
– user3755374
Nov 12 at 7:53
1
Well, as a matter of fact, I work for a company that sells tailor made software solutions, but working with robots sounds like a lot of fun.
– Zohar Peled
Nov 12 at 7:54
Any idea on how I can accomplish this?
– user3755374
Nov 12 at 7:59
1
BTW, don't limit the path to a fixed four directions. A path might very well beS3,N2orN3,E5,S4,W3,N7,S2,W1- In the software industry you should never expect the users to work with the software as they should.
– Zohar Peled
Nov 12 at 8:20
|
show 3 more comments
up vote
-6
down vote
favorite
up vote
-6
down vote
favorite
You work for a company that sells robots that move around a factory floor in a grid like pattern. Your boss has asked you to write a program that will test how many unique squares a robot visits given a set of instructions.
For example the input N4,E2,S2,W4 (described below) should result in a value of 11.
The robot starts at position 1, heads north for four blocks, east for two blocks, south for two and west for four. During those steps it visits blocks 1-12 once except for block 2 which it visits twice. Block 2 should only be counted once. The size of the grid is unknown and not given in the input.
I have tried the below but is not getting unique values.I also want a way to get the input in the formart N4,E2,S2,W4 not with separate prompts for direction.
static void Main(string args)
{
int x1 = 0;
int y1 = 0;
int x2 = 0;
int y2 = 0;
int x3 = 0;
int y3 = 0;
int x4 = 0;
int y4 = 0;
int N, S, E, W, Total;
string coordinate1, coordinate2, coordinate3, coordinate4;
Console.Write("Enter North : ");
N = int.Parse(Console.ReadLine());
if(N != 0)
{
x1 += 0;
y1 += N;
}
coordinate1 = "(" + x1 + "," + y1 + ")";
Console.Write("Enter East: ");
E = int.Parse(Console.ReadLine());
if (E != 0)
{
y3 += 0;
x3 += E;
}
coordinate3 = "(" + x3 + "," + y3 + ")";
Console.Write("Enter South: ");
S = int.Parse(Console.ReadLine());
if (S != 0)
{
x2 += 0;
y2 -= S;
}
coordinate2 = "(" + x2 + "," + y2 + ")";
Console.Write("Enter West: ");
W = int.Parse(Console.ReadLine());
if (W != 0)
{
y4 += 0;
x4 -= W;
}
coordinate4 = "(" + x4 + "," + y4 + ")";
if (coordinate1 == coordinate2|| coordinate1== coordinate3 || coordinate1 == coordinate4 || coordinate2 == coordinate3 || coordinate2 == coordinate4 || coordinate3 ==coordinate4 )
{
Total = (N + S + E + W) - 1 ;
Console.WriteLine("The total Blocks travelled are " + Total);
}
else
{
Total = N + S + E + W;
Console.WriteLine("The total Blocks travelled are " + Total);
}
}
c#
You work for a company that sells robots that move around a factory floor in a grid like pattern. Your boss has asked you to write a program that will test how many unique squares a robot visits given a set of instructions.
For example the input N4,E2,S2,W4 (described below) should result in a value of 11.
The robot starts at position 1, heads north for four blocks, east for two blocks, south for two and west for four. During those steps it visits blocks 1-12 once except for block 2 which it visits twice. Block 2 should only be counted once. The size of the grid is unknown and not given in the input.
I have tried the below but is not getting unique values.I also want a way to get the input in the formart N4,E2,S2,W4 not with separate prompts for direction.
static void Main(string args)
{
int x1 = 0;
int y1 = 0;
int x2 = 0;
int y2 = 0;
int x3 = 0;
int y3 = 0;
int x4 = 0;
int y4 = 0;
int N, S, E, W, Total;
string coordinate1, coordinate2, coordinate3, coordinate4;
Console.Write("Enter North : ");
N = int.Parse(Console.ReadLine());
if(N != 0)
{
x1 += 0;
y1 += N;
}
coordinate1 = "(" + x1 + "," + y1 + ")";
Console.Write("Enter East: ");
E = int.Parse(Console.ReadLine());
if (E != 0)
{
y3 += 0;
x3 += E;
}
coordinate3 = "(" + x3 + "," + y3 + ")";
Console.Write("Enter South: ");
S = int.Parse(Console.ReadLine());
if (S != 0)
{
x2 += 0;
y2 -= S;
}
coordinate2 = "(" + x2 + "," + y2 + ")";
Console.Write("Enter West: ");
W = int.Parse(Console.ReadLine());
if (W != 0)
{
y4 += 0;
x4 -= W;
}
coordinate4 = "(" + x4 + "," + y4 + ")";
if (coordinate1 == coordinate2|| coordinate1== coordinate3 || coordinate1 == coordinate4 || coordinate2 == coordinate3 || coordinate2 == coordinate4 || coordinate3 ==coordinate4 )
{
Total = (N + S + E + W) - 1 ;
Console.WriteLine("The total Blocks travelled are " + Total);
}
else
{
Total = N + S + E + W;
Console.WriteLine("The total Blocks travelled are " + Total);
}
}
c#
c#
edited Nov 12 at 7:53
asked Nov 12 at 7:43
user3755374
15
15
closed as too broad by Steve, tripleee, Christian Gollhardt, jww, Tetsuya Yamamoto Nov 12 at 8:22
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as too broad by Steve, tripleee, Christian Gollhardt, jww, Tetsuya Yamamoto Nov 12 at 8:22
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
2
We aren't going to do your homework for you. Have you tried anything yet? Where exactly are you stuck?
– Mureinik
Nov 12 at 7:46
I have added the sample code of what i have tried please help.
– user3755374
Nov 12 at 7:53
1
Well, as a matter of fact, I work for a company that sells tailor made software solutions, but working with robots sounds like a lot of fun.
– Zohar Peled
Nov 12 at 7:54
Any idea on how I can accomplish this?
– user3755374
Nov 12 at 7:59
1
BTW, don't limit the path to a fixed four directions. A path might very well beS3,N2orN3,E5,S4,W3,N7,S2,W1- In the software industry you should never expect the users to work with the software as they should.
– Zohar Peled
Nov 12 at 8:20
|
show 3 more comments
2
We aren't going to do your homework for you. Have you tried anything yet? Where exactly are you stuck?
– Mureinik
Nov 12 at 7:46
I have added the sample code of what i have tried please help.
– user3755374
Nov 12 at 7:53
1
Well, as a matter of fact, I work for a company that sells tailor made software solutions, but working with robots sounds like a lot of fun.
– Zohar Peled
Nov 12 at 7:54
Any idea on how I can accomplish this?
– user3755374
Nov 12 at 7:59
1
BTW, don't limit the path to a fixed four directions. A path might very well beS3,N2orN3,E5,S4,W3,N7,S2,W1- In the software industry you should never expect the users to work with the software as they should.
– Zohar Peled
Nov 12 at 8:20
2
2
We aren't going to do your homework for you. Have you tried anything yet? Where exactly are you stuck?
– Mureinik
Nov 12 at 7:46
We aren't going to do your homework for you. Have you tried anything yet? Where exactly are you stuck?
– Mureinik
Nov 12 at 7:46
I have added the sample code of what i have tried please help.
– user3755374
Nov 12 at 7:53
I have added the sample code of what i have tried please help.
– user3755374
Nov 12 at 7:53
1
1
Well, as a matter of fact, I work for a company that sells tailor made software solutions, but working with robots sounds like a lot of fun.
– Zohar Peled
Nov 12 at 7:54
Well, as a matter of fact, I work for a company that sells tailor made software solutions, but working with robots sounds like a lot of fun.
– Zohar Peled
Nov 12 at 7:54
Any idea on how I can accomplish this?
– user3755374
Nov 12 at 7:59
Any idea on how I can accomplish this?
– user3755374
Nov 12 at 7:59
1
1
BTW, don't limit the path to a fixed four directions. A path might very well be
S3,N2 or N3,E5,S4,W3,N7,S2,W1 - In the software industry you should never expect the users to work with the software as they should.– Zohar Peled
Nov 12 at 8:20
BTW, don't limit the path to a fixed four directions. A path might very well be
S3,N2 or N3,E5,S4,W3,N7,S2,W1 - In the software industry you should never expect the users to work with the software as they should.– Zohar Peled
Nov 12 at 8:20
|
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
This is clearly a homework exercise so I will not provide any code in this answer, only an explanation on how to approach it.
So, since the floor is a grid with unknown size, you must assume an infinite graph where your robot starts at (0,0):
N
|
|
W------+------E
|
|
S
Now, each step the robot takes in each direction it lends on a point in the graph - say the instructions are N4 - you add the points (1,0), (2,0), (3,0),(4,0) to your already existing (0,0) point. Then you move E2 - add (4,1) and (4,2) to the collection of points. Next S5 so you add (3,2), (2,2) (1, 2), (0, 2), (-1, 2) to the collection and so on. Each direction only changes one coordinate. Then all you have to do is count the number of the distinct coordinates and you're done.
Hint: For this exercise you might want to only collect the distinct points (you can use a HashSet for this), but when designing a software you must think beyond current requirements since customers rarely know what they want and even more what they actually need. In this case, you better collect all the points even if they are duplicates and even if this is not needed for this specific task, because the next exercise might very well be to recreate the instruction based on the robot's path, and for that it would be easier to rebuild it from the full set of coordinates. On that note, you would want to save the points in a collection that provides index based access like a List.
Thanks Zohar, even if it is a homework,Can you show me as code example I am not proficient in C# i am still learning.
– user3755374
Nov 12 at 8:42
1
I can but if I do that you will not learn. There is only one way of learning how to do something and that's to do it yourself. Give it a try, if you get stuck somewhere come back and ask a new, more specific question. chances are someone will answer it.
– Zohar Peled
Nov 12 at 8:56
@user3755374 start with reading a single command string ("N4,E31"). Then use String.Split to get separate commands. Print them ("N4", "E31"). Next step: decode the commands and print them as "North, 4 steps" (etc). Next step: print all locations you visit, assuming you start from (0,0) - "N4" visits 4 locations! Don't try and create the final solution at once, split the problem into small steps that you can solve and slowly build towards the solution.
– Hans Kesting
Nov 12 at 9:23
i understand,so if i enter N4, how must i add this points (1,0), (2,0), (3,0),(4,0)?
– user3755374
Nov 12 at 9:25
Yes, that's correct. Conventionally, in geography, theNis facing up andEis facing left - and in Math, when you draw a graph, theYis facing up andXis facing left - so(1,0)isY1, X0orN1, E0.
– Zohar Peled
Nov 12 at 9:27
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
This is clearly a homework exercise so I will not provide any code in this answer, only an explanation on how to approach it.
So, since the floor is a grid with unknown size, you must assume an infinite graph where your robot starts at (0,0):
N
|
|
W------+------E
|
|
S
Now, each step the robot takes in each direction it lends on a point in the graph - say the instructions are N4 - you add the points (1,0), (2,0), (3,0),(4,0) to your already existing (0,0) point. Then you move E2 - add (4,1) and (4,2) to the collection of points. Next S5 so you add (3,2), (2,2) (1, 2), (0, 2), (-1, 2) to the collection and so on. Each direction only changes one coordinate. Then all you have to do is count the number of the distinct coordinates and you're done.
Hint: For this exercise you might want to only collect the distinct points (you can use a HashSet for this), but when designing a software you must think beyond current requirements since customers rarely know what they want and even more what they actually need. In this case, you better collect all the points even if they are duplicates and even if this is not needed for this specific task, because the next exercise might very well be to recreate the instruction based on the robot's path, and for that it would be easier to rebuild it from the full set of coordinates. On that note, you would want to save the points in a collection that provides index based access like a List.
Thanks Zohar, even if it is a homework,Can you show me as code example I am not proficient in C# i am still learning.
– user3755374
Nov 12 at 8:42
1
I can but if I do that you will not learn. There is only one way of learning how to do something and that's to do it yourself. Give it a try, if you get stuck somewhere come back and ask a new, more specific question. chances are someone will answer it.
– Zohar Peled
Nov 12 at 8:56
@user3755374 start with reading a single command string ("N4,E31"). Then use String.Split to get separate commands. Print them ("N4", "E31"). Next step: decode the commands and print them as "North, 4 steps" (etc). Next step: print all locations you visit, assuming you start from (0,0) - "N4" visits 4 locations! Don't try and create the final solution at once, split the problem into small steps that you can solve and slowly build towards the solution.
– Hans Kesting
Nov 12 at 9:23
i understand,so if i enter N4, how must i add this points (1,0), (2,0), (3,0),(4,0)?
– user3755374
Nov 12 at 9:25
Yes, that's correct. Conventionally, in geography, theNis facing up andEis facing left - and in Math, when you draw a graph, theYis facing up andXis facing left - so(1,0)isY1, X0orN1, E0.
– Zohar Peled
Nov 12 at 9:27
add a comment |
up vote
1
down vote
This is clearly a homework exercise so I will not provide any code in this answer, only an explanation on how to approach it.
So, since the floor is a grid with unknown size, you must assume an infinite graph where your robot starts at (0,0):
N
|
|
W------+------E
|
|
S
Now, each step the robot takes in each direction it lends on a point in the graph - say the instructions are N4 - you add the points (1,0), (2,0), (3,0),(4,0) to your already existing (0,0) point. Then you move E2 - add (4,1) and (4,2) to the collection of points. Next S5 so you add (3,2), (2,2) (1, 2), (0, 2), (-1, 2) to the collection and so on. Each direction only changes one coordinate. Then all you have to do is count the number of the distinct coordinates and you're done.
Hint: For this exercise you might want to only collect the distinct points (you can use a HashSet for this), but when designing a software you must think beyond current requirements since customers rarely know what they want and even more what they actually need. In this case, you better collect all the points even if they are duplicates and even if this is not needed for this specific task, because the next exercise might very well be to recreate the instruction based on the robot's path, and for that it would be easier to rebuild it from the full set of coordinates. On that note, you would want to save the points in a collection that provides index based access like a List.
Thanks Zohar, even if it is a homework,Can you show me as code example I am not proficient in C# i am still learning.
– user3755374
Nov 12 at 8:42
1
I can but if I do that you will not learn. There is only one way of learning how to do something and that's to do it yourself. Give it a try, if you get stuck somewhere come back and ask a new, more specific question. chances are someone will answer it.
– Zohar Peled
Nov 12 at 8:56
@user3755374 start with reading a single command string ("N4,E31"). Then use String.Split to get separate commands. Print them ("N4", "E31"). Next step: decode the commands and print them as "North, 4 steps" (etc). Next step: print all locations you visit, assuming you start from (0,0) - "N4" visits 4 locations! Don't try and create the final solution at once, split the problem into small steps that you can solve and slowly build towards the solution.
– Hans Kesting
Nov 12 at 9:23
i understand,so if i enter N4, how must i add this points (1,0), (2,0), (3,0),(4,0)?
– user3755374
Nov 12 at 9:25
Yes, that's correct. Conventionally, in geography, theNis facing up andEis facing left - and in Math, when you draw a graph, theYis facing up andXis facing left - so(1,0)isY1, X0orN1, E0.
– Zohar Peled
Nov 12 at 9:27
add a comment |
up vote
1
down vote
up vote
1
down vote
This is clearly a homework exercise so I will not provide any code in this answer, only an explanation on how to approach it.
So, since the floor is a grid with unknown size, you must assume an infinite graph where your robot starts at (0,0):
N
|
|
W------+------E
|
|
S
Now, each step the robot takes in each direction it lends on a point in the graph - say the instructions are N4 - you add the points (1,0), (2,0), (3,0),(4,0) to your already existing (0,0) point. Then you move E2 - add (4,1) and (4,2) to the collection of points. Next S5 so you add (3,2), (2,2) (1, 2), (0, 2), (-1, 2) to the collection and so on. Each direction only changes one coordinate. Then all you have to do is count the number of the distinct coordinates and you're done.
Hint: For this exercise you might want to only collect the distinct points (you can use a HashSet for this), but when designing a software you must think beyond current requirements since customers rarely know what they want and even more what they actually need. In this case, you better collect all the points even if they are duplicates and even if this is not needed for this specific task, because the next exercise might very well be to recreate the instruction based on the robot's path, and for that it would be easier to rebuild it from the full set of coordinates. On that note, you would want to save the points in a collection that provides index based access like a List.
This is clearly a homework exercise so I will not provide any code in this answer, only an explanation on how to approach it.
So, since the floor is a grid with unknown size, you must assume an infinite graph where your robot starts at (0,0):
N
|
|
W------+------E
|
|
S
Now, each step the robot takes in each direction it lends on a point in the graph - say the instructions are N4 - you add the points (1,0), (2,0), (3,0),(4,0) to your already existing (0,0) point. Then you move E2 - add (4,1) and (4,2) to the collection of points. Next S5 so you add (3,2), (2,2) (1, 2), (0, 2), (-1, 2) to the collection and so on. Each direction only changes one coordinate. Then all you have to do is count the number of the distinct coordinates and you're done.
Hint: For this exercise you might want to only collect the distinct points (you can use a HashSet for this), but when designing a software you must think beyond current requirements since customers rarely know what they want and even more what they actually need. In this case, you better collect all the points even if they are duplicates and even if this is not needed for this specific task, because the next exercise might very well be to recreate the instruction based on the robot's path, and for that it would be easier to rebuild it from the full set of coordinates. On that note, you would want to save the points in a collection that provides index based access like a List.
answered Nov 12 at 8:17
Zohar Peled
52.1k73273
52.1k73273
Thanks Zohar, even if it is a homework,Can you show me as code example I am not proficient in C# i am still learning.
– user3755374
Nov 12 at 8:42
1
I can but if I do that you will not learn. There is only one way of learning how to do something and that's to do it yourself. Give it a try, if you get stuck somewhere come back and ask a new, more specific question. chances are someone will answer it.
– Zohar Peled
Nov 12 at 8:56
@user3755374 start with reading a single command string ("N4,E31"). Then use String.Split to get separate commands. Print them ("N4", "E31"). Next step: decode the commands and print them as "North, 4 steps" (etc). Next step: print all locations you visit, assuming you start from (0,0) - "N4" visits 4 locations! Don't try and create the final solution at once, split the problem into small steps that you can solve and slowly build towards the solution.
– Hans Kesting
Nov 12 at 9:23
i understand,so if i enter N4, how must i add this points (1,0), (2,0), (3,0),(4,0)?
– user3755374
Nov 12 at 9:25
Yes, that's correct. Conventionally, in geography, theNis facing up andEis facing left - and in Math, when you draw a graph, theYis facing up andXis facing left - so(1,0)isY1, X0orN1, E0.
– Zohar Peled
Nov 12 at 9:27
add a comment |
Thanks Zohar, even if it is a homework,Can you show me as code example I am not proficient in C# i am still learning.
– user3755374
Nov 12 at 8:42
1
I can but if I do that you will not learn. There is only one way of learning how to do something and that's to do it yourself. Give it a try, if you get stuck somewhere come back and ask a new, more specific question. chances are someone will answer it.
– Zohar Peled
Nov 12 at 8:56
@user3755374 start with reading a single command string ("N4,E31"). Then use String.Split to get separate commands. Print them ("N4", "E31"). Next step: decode the commands and print them as "North, 4 steps" (etc). Next step: print all locations you visit, assuming you start from (0,0) - "N4" visits 4 locations! Don't try and create the final solution at once, split the problem into small steps that you can solve and slowly build towards the solution.
– Hans Kesting
Nov 12 at 9:23
i understand,so if i enter N4, how must i add this points (1,0), (2,0), (3,0),(4,0)?
– user3755374
Nov 12 at 9:25
Yes, that's correct. Conventionally, in geography, theNis facing up andEis facing left - and in Math, when you draw a graph, theYis facing up andXis facing left - so(1,0)isY1, X0orN1, E0.
– Zohar Peled
Nov 12 at 9:27
Thanks Zohar, even if it is a homework,Can you show me as code example I am not proficient in C# i am still learning.
– user3755374
Nov 12 at 8:42
Thanks Zohar, even if it is a homework,Can you show me as code example I am not proficient in C# i am still learning.
– user3755374
Nov 12 at 8:42
1
1
I can but if I do that you will not learn. There is only one way of learning how to do something and that's to do it yourself. Give it a try, if you get stuck somewhere come back and ask a new, more specific question. chances are someone will answer it.
– Zohar Peled
Nov 12 at 8:56
I can but if I do that you will not learn. There is only one way of learning how to do something and that's to do it yourself. Give it a try, if you get stuck somewhere come back and ask a new, more specific question. chances are someone will answer it.
– Zohar Peled
Nov 12 at 8:56
@user3755374 start with reading a single command string ("N4,E31"). Then use String.Split to get separate commands. Print them ("N4", "E31"). Next step: decode the commands and print them as "North, 4 steps" (etc). Next step: print all locations you visit, assuming you start from (0,0) - "N4" visits 4 locations! Don't try and create the final solution at once, split the problem into small steps that you can solve and slowly build towards the solution.
– Hans Kesting
Nov 12 at 9:23
@user3755374 start with reading a single command string ("N4,E31"). Then use String.Split to get separate commands. Print them ("N4", "E31"). Next step: decode the commands and print them as "North, 4 steps" (etc). Next step: print all locations you visit, assuming you start from (0,0) - "N4" visits 4 locations! Don't try and create the final solution at once, split the problem into small steps that you can solve and slowly build towards the solution.
– Hans Kesting
Nov 12 at 9:23
i understand,so if i enter N4, how must i add this points (1,0), (2,0), (3,0),(4,0)?
– user3755374
Nov 12 at 9:25
i understand,so if i enter N4, how must i add this points (1,0), (2,0), (3,0),(4,0)?
– user3755374
Nov 12 at 9:25
Yes, that's correct. Conventionally, in geography, the
N is facing up and E is facing left - and in Math, when you draw a graph, the Y is facing up and X is facing left - so (1,0) is Y1, X0 or N1, E0.– Zohar Peled
Nov 12 at 9:27
Yes, that's correct. Conventionally, in geography, the
N is facing up and E is facing left - and in Math, when you draw a graph, the Y is facing up and X is facing left - so (1,0) is Y1, X0 or N1, E0.– Zohar Peled
Nov 12 at 9:27
add a comment |
2
We aren't going to do your homework for you. Have you tried anything yet? Where exactly are you stuck?
– Mureinik
Nov 12 at 7:46
I have added the sample code of what i have tried please help.
– user3755374
Nov 12 at 7:53
1
Well, as a matter of fact, I work for a company that sells tailor made software solutions, but working with robots sounds like a lot of fun.
– Zohar Peled
Nov 12 at 7:54
Any idea on how I can accomplish this?
– user3755374
Nov 12 at 7:59
1
BTW, don't limit the path to a fixed four directions. A path might very well be
S3,N2orN3,E5,S4,W3,N7,S2,W1- In the software industry you should never expect the users to work with the software as they should.– Zohar Peled
Nov 12 at 8:20