Code requirements:
A robot is positioned on an integral point in a two-dimensional coordinate grid (xr, yr). There is a treasure that has been placed at a point in the same grid at (xt, yt). All x’s and y’s will be integral values. The robot can move up (North), down (South), left (West), or right (East). Commands can be given to the robot to move one position in one of the four direction. That is, “E” moves a robot one slot East (to the right) so if the robot was on position (3, 4), it would now be on (4, 4). The command N would move the robot one position north so a robot at position (4, 4) would be at (4, 5). Because the robot cannot move diagonally, the shortest distance between a robot at (xr, yr) and a treasure at (xt, yt) is | xr – xt | + | yr - yt | = ShortestPossibleDistance Write a recursive
/
/
/
/
This is a C++ program. I was using this solution I found as a reference and used concepts from it to build my code, but I couldn't figure out how to incorporate the Max Distance without getting a bunch of errors (this code doesn't include max distance). That's all I need solved. Read the assignment and just post the reworked solution with MaxDistance in it, thanks!
#include
#include
using namespace std;
int findPermutations(string str, int index, int n,int counts)
{
if (index >= n) {
cout << str << endl;
return 1+counts;
}
for (int i = index; i < n; i++) {
bool check=true;
for (int j = index; j < i; j++)
{
if (str[j] == str[i])
{
check=false;
}
}
if (check) {
char temp=str[index];
str[index]=str[i];
str[i]=temp;
counts=findPermutations(str, index + 1, n,counts);
temp=str[index];
str[index]=str[i];
str[i]=temp;
}
}
return counts;
}
int main()
{
int x1,x2,y1,y2,counts=0;
string s="";
char str[100];
cout<<"Enter the coordinates as x1 y1 x2 y2 where x1 and y1 are initial and x2 and y2 are final: ";
cin>>x1>>y1>>x2>>y2;
if(x2>x1)
{
for(int i=0;i<(x2-x1);i++)
{
s=s+"E";
}
}
else
{
for(int i=0;i<(x1-x2);i++)
{
s=s+"W";
}
}
if(y2>y1)
{
for(int i=0;i<(y2-y1);i++)
{
s=s+"N";
}
}
else
{
for(int i=0;i<(y1-y2);i++)
{
s=s+"S";
}
}
int n = s.length();
cout<<"Number of paths are: "< return 0;
}
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images
- In the realm of computer science, what differentiates range control from null control is the use of different types of controls.arrow_forwardIn object-oriented programming, a(n) is a request to execute a specific method and return a response.arrow_forward8. A game is played by moving a game piece left or right along a horizontal game board. The board consists of spaces of various colors, as shown. The circle represents the initial location of the game piece. Yellow Black Green Green Red Yellow Black Black Yellow Black The following algorithm indicates how the game is played. The game continues until the game is either won by landing on the red space or lost when the piece moves off either end of the board. Step 1: Place a game piece on a space that is not red and set a counter to 0. Step 2: If the game piece is on a yellow space, move the game piece 3 positions to the left and go to step 3. Otherwise, if the game piece is on a black space, move the game piece 1 position to the left and go to step 3. Otherwise, if the game piece is on a green space, move the game piece 2 positions to the right and go to step 3. Step 3: Increase the value of the counter by 1. Step 4: If game piece is on the red space or moved off the end of the game…arrow_forward
- Object-oriented programming and design patterns have a link that must be described in further depth.arrow_forwardComputer Science UML is a standard language that allows you to capture different aspects of your system in well-defined graphical models. Some of the models capture static aspects for the system and one will capture dynamic behavior for the system. In this project, you are required to draw an activity diagram showing the actions and events involved in depositing a check to a bank account using a mobile app. In particular, your paper should provide the following: A simple pseudo-code that captures the sequence of that process A detailed activity diagram that maps to your pseudo code you identified Make sure to specify clearly any assumptions you feel important to understand your logic I'm a bit lost on what to do and really just need an example of what this is asking and then suggestions on how to go about doing the assignment.arrow_forwardPart C: Function, for and plotting We did a project in the lecture on calculating the free fall speeds and plotting them on a graph. This part is similar to the project. An engineer has derived a relationship between the force applied to a material and the extension in length that the force would cause. The relationship between force f and extension e is given by: You are asked to plot a graph showing the relationship between force and extension. You are asked to complete the following tasks: Task 1 Write a Python function which returns the value of e for a given input f. Do not use literals (e.g. 5.5, 10) in the expressions for e in the function. Instead you should define constants and use them. Note that the relationship between e and f depends on whether f is bigger than 10 or not, this means you need a certain Python construction in your function. If you can't think of that, have a look at Part A of Lab03.arrow_forward
- Computer Science Investing in stocks is a way to create assets that are supposed to provide financial security over time. In solving this problem, we assume that an investor buys several shares of stock at a certain price. These shares are going to be sold later on for a different price. Obviously, if the selling price is higher than the acquisition price, the investor makes a profit, registering capital gain. If the shares are sold at a lower price, the investor has a loss, which marks a negative capital gain. This whole process is done over a period of time, and you are required to create a scenario for buying and selling shares. The assumption is that the investor sells shares in the order in which they were purchased. The goal is to calculate the capital gain over time. Suppose that you buy n shares of stock or mutual fund for d dollars each. Later, you sell some of these shares. If the sale price exceeds the purchase price, you have made a profit—a capital gain. On the other…arrow_forwardIt is an amusement-oriented computer-controlled game in which players engage with objects displayed on a computer screen: Please suggest one (1) acceptable input device and one (1) suitable output device, together with instructions on how to use each, if we wish to play games on the computer.arrow_forwardIn the computer programming field, the terms "cohesion" and "coupling" are used interchangeably.arrow_forward
- Description of animation In informal language, here is an example description of the animation for the "Simple Animation": Create red rectangle R with corner at (200,200), width 50and height 100 Create blue oval C with center at (500,100), radius 60 and30 R appears at time t=1 and disappears at time t=100 C appears at time t=6 and disappears at time t=100 R moves from (200,200) to (300,300) from time t=10 to t=50 C moves from (500,100) to (500,400) from time t=20 to t=70 C changes from blue to green from time t=50 to t=80 R moves from (300,300) to (200,200) from time t=70 tot=100 R changes width from 50 to 25 from time t=51 to t=70 We use a time reference for each step in the animation. This time reference is usually unitless, which helps us in describing animation without mentioning its absolute speed. Further, the animation must adhere to certain constraints. For example, one cannot have move the same rectangle to the left and right during overlapping…arrow_forwardBlue-Eyed Island: A bunch of people are living on an island, when a visitor comes with a strangeorder: all blue-eyed people must leave the island as soon as possible. There will be a flight out at8:00pm every evening. Each person can see everyone else's eye color, but they do not know theirown (nor is anyone allowed to tell them). Additionally, they do not know how many people haveblue eyes, although they do know that at least one person does. How many days will it take theblue-eyed people to leave?arrow_forwardA robot is a programmable machine that can carry out a series of automated tasks. The final lab for the semester is to build a robot of your own design. Your robot should contain at least two sensors, and two output mechanisms that work together to perform a task. Sensors can be something like a temperature or light sensor. Output mechanisms can be things like servo motors or lights. In order to make sure that the task your robot performs is sufficiently complex to meet the objectives of the course you will need to write a proposal that answers the questions below.1. Describe the purpose or goal of your robot. Answer the question, “Why does this robot exist?” What problem does it solve? What are some of the challenges to solving that problem?2. Describe how your robot will solve the problem. What sensors will it use? How will it behave based on the inputs and how will it overcome the challenges presented?3. How will you know if your robot successfully meets its goals? What tests will…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education