SlideShare a Scribd company logo
1 of 10
Download to read offline
Please answer in C! I provided my current code, my code is currently not painting the room with
values from A to 'Z'
Jethro and Cletus are quarantined at home and bored. They spend most of their day sitting
at their computer monitor working or browsing the internet in their small apartment. Out of
boredom Jethro begins counting the number of steps needed to reach each location in their
small apartment. After seeing that taking different paths from their computer to their coffee
maker yields different numbers of steps a question dawns on them. They want to know what
is the fewest number of steps needed to reach all of the locations in their small apartment
starting from their computer.
Fortunately, Jethro is quite skilled at ASCII art. So they model their room with ASCII
characters. A space can be moved through. An asterisk * is a wall or furniture that
cannot be traversed (no climbing over furniture!). Going up, down, left, right one space
takes exactly one step (well assume no diagonal movements for that sake of simplicity). For
example, here is a possible model of their room:
**************
* A *
* * *
* * *
* *** *
* *
* ***** *
* *** *
**************
Assume that (0, 0) is the upper lefthand corner. For the sake of simplicity you can assume
the apartment is enclosed in * characters and that the location of Jethros computer has
been marked with an A.
Jethro is still new to programming and wants to hire you to write the program to label all
of the locations in their apartment with the minimum number of steps needed to reach
them. To keep with the ASCII art theme youll use the letters A-Z Such that:
A is 0 steps
B is 1 step
C is 2 steps
...
Y is 24 steps
Z is 25 (or more) steps
Heres some example rooms:
Example 1:
Base room:
*****
*A *
*** *
* *
*****
Room after algorithm:
*****
*ABC*
***D*
*GFE*
*****
(We cant pass through the * symbols)
Example 2:
Base room:
**************
* A *
* * *
* * *
* *** *
* *
* ***** *
* *** *
**************
Room after algorithm:
**************
*BABCDEFGHIJK*
*CBCD*FGHIJKL*
*DCDE*GHIJKLM*
*ED***HIJKLMN*
*FEFGHIJKLMNO*
*GFGHI*****OP*
*HGHIJ***RQPQ*
**************
Example 3:
Base room:
**********************************
* A *
**********************************
Room after algorithm:
**********************************
*DCBABCDEFGHIJKLMNOPQRSTUVWXYZZZZ*
**********************************
(We dont count past Z since Jethro has a pretty small apartment)
Example 4:
Base room:
*******
*A *
**** *
* * *
**** *
* *
*******
Room after algorithm:
*******
*ABCDE*
****EF*
* *FG*
****GH*
*KJIHI*
*******
(Unreachable areas should remain unchanged)Heres some example rooms:
Example 1:
Base room:
*****
*A *
*** *
* *
*****
Room after algorithm:
*****
*ABC*
***D*
*GFE*
*****
(We cant pass through the * symbols)
Example 2:
Base room:
**************
* A *
* * *
* * *
* *** *
* *
* ***** *
* *** *
**************
Room after algorithm:
**************
*BABCDEFGHIJK*
*CBCD*FGHIJKL*
*DCDE*GHIJKLM*
*ED***HIJKLMN*
*FEFGHIJKLMNO*
*GFGHI*****OP*
*HGHIJ***RQPQ*
**************
Example 3:
Base room:
**********************************
* A *
**********************************
Room after algorithm:
**********************************
*DCBABCDEFGHIJKLMNOPQRSTUVWXYZZZZ*
**********************************
(We dont count past Z since Jethro has a pretty small apartment)
Example 4:
Base room:
*******
*A *
**** *
* * *
**** *
* *
*******
Room after algorithm:
*******
*ABCDE*
****EF*
* *FG*
****GH*
*KJIHI*
*******
(Unreachable areas should remain unchanged)
Part 1 - Programming: (15 points)
Write a brute force recursive program to solve the problem described above in paintRoom.c.
Hint 1: This program will take fewer lines of code than previous one but youll need to
think about and test them carefully. For reference, my recP aintRoom only had 10 lines of
code in it.
Hint 2: From any given space, you need to try to continue moving up, down, left, and right
(i.e. 4 recursive calls).
Hint 3: Your algorithm can move into a *, but upon recognizing it as an obstacle, it should
return from that call.
Hint 4: It may help to track the distance traveled so far from the starting A character.
Hint 5: Only updating locations that contain a wont be enough. Sometimes youll need
to update a location you previously visited and labeled.
Hint 6: chars can be treated like small valued integers. In particular, it may be helpful to
use operations like + and <= with your chars.
PROGRAMS
driver.c
#include
#include
#include
#include "paintRoom.h"
RoomData read2DArray( const char* name );
void print2DArray( RoomData room );
void free2DArray( RoomData room );
/* change the following constants to add/remove some cases for testing */
const int numFiles = 8;
const char *defaultFilenames[] = { "room-Small01.txt", "room-Small02.txt", "room-
Medium01.txt", "room-Medium02.txt", "room-Long01.txt", "room-Long02.txt", "room-
Large01.txt", "room-Large02.txt" };
const bool enableFilenames[] = { true , true , true , true , true
, true , true , true };
/* DO NOT MODIFY THIS FILE */
int main( int argc, char *argv[] )
{
int i;
RoomData room;
printName( );
printf("Running default test files: nn");
for( i=0; i
#include
/* DO NOT MODIFY THIS FILE */
typedef struct RoomData
{
char **roomArray; /* the 2d char array representing the room shared by Jethro and Cletus
*/
int numrows; /* the number of rows for the char** roomArray */
int numcols; /* the number of columns for the char** roomArray */
} RoomData;
void printName( );
void paintRoom( RoomData room );
#endif
paintroom.c
#include "paintRoom.h"
void recPaintRoom( RoomData room, int row, int col, int distanceFromA /*feel free to
remove/add any other parameters here*/ );
/*declare any other helper functions here*/
/* printName
* input: none
* output: none
*
* Prints name the student who worked on this solution
*/
void printName( )
{
/* TODO : Fill in your name*/
printf("nThis solution was completed by:n");
printf("student namen");
}
/* TODO
* paintRoom
* input: the room to process
* output: N/A
*
* This non-recursive function is called by the driver and it makes the initial call to recursive
function recPaintRoom.
*/
void paintRoom( RoomData room )
{
/* Call any other helper functions (a helper function to find the location of 'A' in room may be
handy) */
int i;
int j;
/* Find starting location */
int startRow = -1;
int startCol = -1;
for( i = 0; i < room.numrows; i++ ){
for( j = 0; j < room.numcols; j++ ) {
if( room.roomArray[i][j] == 'A') { /*STOPPING POINT
USE FUNCTIONS IN MAKE FILE NOT .roomArray NEXT */
startRow = i;
startCol = j;
break;
}
}
if( startRow != -1) {
break;
}
}
/*Call your recursive function here */
if( startRow != -1) {
int currentValue = 0;
recPaintRoom( room, startRow, startCol, currentValue);
}
}
/* TODO
* recPaintRoom
* input: the room to process, the row and column of the current location being explored, the
distance traveled from 'A'
* output: N/A
*/
void recPaintRoom( RoomData room, int row, int col, int distanceFromA )
{
/* debugging output */
printf("Exploring (%d,%d) with label '%c'n", row, col, distanceFromA );
/* Base cases: */
if( row < 0 || row >= room.numrows || col < 0 || col >= room.numcols ||
room.roomArray[row][col] == '*') {
return;
}
/*Check if current location is an obstacle or already labeled */
if( room.roomArray[row][col] == 'A' || (room.roomArray[row][col] >= 'A' &&
room.roomArray[row][col] <= 'Z' )){
return;
}
else
/* Update label for current location */
room.roomArray[row][col] = distanceFromA;
/* Recursive cases: */
recPaintRoom(room, row - 1, col, distanceFromA + 1); /* Move up */
recPaintRoom(room, row + 1, col, distanceFromA + 1); /* Move down */
recPaintRoom(room, row, col - 1, distanceFromA + 1); /* Move Left */
recPaintRoom(room, row, col + 1, distanceFromA + 1); /* Move Right */
/* Debugging output */
printf("completed rec call with (%d, %d)n", row, col);
}
Find shortest path labeling small apartment locations A-Z

More Related Content

Similar to Find shortest path labeling small apartment locations A-Z

operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfoperating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfaquazac
 
06 -working_with_strings
06  -working_with_strings06  -working_with_strings
06 -working_with_stringsHector Garzo
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4Abed Bukhari
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab ManualAkhilaaReddy
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfaptcomputerzone
 
Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?jonbodner
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicssnelkoli
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docxAdamq0DJonese
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfARCHANASTOREKOTA
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfmallik3000
 
C for Java programmers (part 3)
C for Java programmers (part 3)C for Java programmers (part 3)
C for Java programmers (part 3)Dmitry Zinoviev
 
FITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an endFITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an endThibault Imbert
 
Technology: A Means to an End with Thibault Imbert
Technology: A Means to an End with Thibault ImbertTechnology: A Means to an End with Thibault Imbert
Technology: A Means to an End with Thibault ImbertFITC
 
Print Star pattern in java and print triangle of stars in java
Print Star pattern in java and print triangle of stars in javaPrint Star pattern in java and print triangle of stars in java
Print Star pattern in java and print triangle of stars in javaHiraniahmad
 
Microsoft word java
Microsoft word   javaMicrosoft word   java
Microsoft word javaRavi Purohit
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework HelpC++ Homework Help
 
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays 2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays kinan keshkeh
 

Similar to Find shortest path labeling small apartment locations A-Z (20)

operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfoperating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
 
06 -working_with_strings
06  -working_with_strings06  -working_with_strings
06 -working_with_strings
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
09 Jo P Sep 07
09 Jo P Sep 0709 Jo P Sep 07
09 Jo P Sep 07
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
Kotlin
KotlinKotlin
Kotlin
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdf
 
Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
 
C for Java programmers (part 3)
C for Java programmers (part 3)C for Java programmers (part 3)
C for Java programmers (part 3)
 
FITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an endFITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an end
 
Technology: A Means to an End with Thibault Imbert
Technology: A Means to an End with Thibault ImbertTechnology: A Means to an End with Thibault Imbert
Technology: A Means to an End with Thibault Imbert
 
ch08.ppt
ch08.pptch08.ppt
ch08.ppt
 
Print Star pattern in java and print triangle of stars in java
Print Star pattern in java and print triangle of stars in javaPrint Star pattern in java and print triangle of stars in java
Print Star pattern in java and print triangle of stars in java
 
Microsoft word java
Microsoft word   javaMicrosoft word   java
Microsoft word java
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework Help
 
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays 2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
 

More from support58

Please show me your output. Andrew Kelly has been employed by the We.pdf
Please show me your output. Andrew Kelly has been employed by the We.pdfPlease show me your output. Andrew Kelly has been employed by the We.pdf
Please show me your output. Andrew Kelly has been employed by the We.pdfsupport58
 
Please show me how to do every part of this. Also could you show me .pdf
Please show me how to do every part of this. Also could you show me .pdfPlease show me how to do every part of this. Also could you show me .pdf
Please show me how to do every part of this. Also could you show me .pdfsupport58
 
Please help with the below 3 questions, the python script is at the.pdf
Please help with the below 3  questions, the python script is at the.pdfPlease help with the below 3  questions, the python script is at the.pdf
Please help with the below 3 questions, the python script is at the.pdfsupport58
 
please help! Carmen Company has the following projected costs for .pdf
please help! Carmen Company has the following projected costs for .pdfplease help! Carmen Company has the following projected costs for .pdf
please help! Carmen Company has the following projected costs for .pdfsupport58
 
Please help will upvote. I have a heuristic function that outputs th.pdf
Please help will upvote. I have a heuristic function that outputs th.pdfPlease help will upvote. I have a heuristic function that outputs th.pdf
Please help will upvote. I have a heuristic function that outputs th.pdfsupport58
 
Please create a simple flowchart of this programtell me the necess.pdf
Please create a simple flowchart of this programtell me the necess.pdfPlease create a simple flowchart of this programtell me the necess.pdf
Please create a simple flowchart of this programtell me the necess.pdfsupport58
 
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdfPlease complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdfsupport58
 
Please answer ASAP!!!Research Topic Ransomware attack on k-12 sch.pdf
Please answer ASAP!!!Research Topic Ransomware attack on k-12 sch.pdfPlease answer ASAP!!!Research Topic Ransomware attack on k-12 sch.pdf
Please answer ASAP!!!Research Topic Ransomware attack on k-12 sch.pdfsupport58
 
Plan production for a four-month period (February through May). .pdf
Plan production for a four-month period (February through May). .pdfPlan production for a four-month period (February through May). .pdf
Plan production for a four-month period (February through May). .pdfsupport58
 
Part 1 During the most recent economic crisis in the state of Arizo.pdf
Part 1 During the most recent economic crisis in the state of Arizo.pdfPart 1 During the most recent economic crisis in the state of Arizo.pdf
Part 1 During the most recent economic crisis in the state of Arizo.pdfsupport58
 

More from support58 (11)

Please show me your output. Andrew Kelly has been employed by the We.pdf
Please show me your output. Andrew Kelly has been employed by the We.pdfPlease show me your output. Andrew Kelly has been employed by the We.pdf
Please show me your output. Andrew Kelly has been employed by the We.pdf
 
Please show me how to do every part of this. Also could you show me .pdf
Please show me how to do every part of this. Also could you show me .pdfPlease show me how to do every part of this. Also could you show me .pdf
Please show me how to do every part of this. Also could you show me .pdf
 
Please help with the below 3 questions, the python script is at the.pdf
Please help with the below 3  questions, the python script is at the.pdfPlease help with the below 3  questions, the python script is at the.pdf
Please help with the below 3 questions, the python script is at the.pdf
 
please help! Carmen Company has the following projected costs for .pdf
please help! Carmen Company has the following projected costs for .pdfplease help! Carmen Company has the following projected costs for .pdf
please help! Carmen Company has the following projected costs for .pdf
 
Please help will upvote. I have a heuristic function that outputs th.pdf
Please help will upvote. I have a heuristic function that outputs th.pdfPlease help will upvote. I have a heuristic function that outputs th.pdf
Please help will upvote. I have a heuristic function that outputs th.pdf
 
Please create a simple flowchart of this programtell me the necess.pdf
Please create a simple flowchart of this programtell me the necess.pdfPlease create a simple flowchart of this programtell me the necess.pdf
Please create a simple flowchart of this programtell me the necess.pdf
 
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdfPlease complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
 
Please answer ASAP!!!Research Topic Ransomware attack on k-12 sch.pdf
Please answer ASAP!!!Research Topic Ransomware attack on k-12 sch.pdfPlease answer ASAP!!!Research Topic Ransomware attack on k-12 sch.pdf
Please answer ASAP!!!Research Topic Ransomware attack on k-12 sch.pdf
 
Plan production for a four-month period (February through May). .pdf
Plan production for a four-month period (February through May). .pdfPlan production for a four-month period (February through May). .pdf
Plan production for a four-month period (February through May). .pdf
 
Part I.pdf
Part I.pdfPart I.pdf
Part I.pdf
 
Part 1 During the most recent economic crisis in the state of Arizo.pdf
Part 1 During the most recent economic crisis in the state of Arizo.pdfPart 1 During the most recent economic crisis in the state of Arizo.pdf
Part 1 During the most recent economic crisis in the state of Arizo.pdf
 

Recently uploaded

Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 

Recently uploaded (20)

Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 

Find shortest path labeling small apartment locations A-Z

  • 1. Please answer in C! I provided my current code, my code is currently not painting the room with values from A to 'Z' Jethro and Cletus are quarantined at home and bored. They spend most of their day sitting at their computer monitor working or browsing the internet in their small apartment. Out of boredom Jethro begins counting the number of steps needed to reach each location in their small apartment. After seeing that taking different paths from their computer to their coffee maker yields different numbers of steps a question dawns on them. They want to know what is the fewest number of steps needed to reach all of the locations in their small apartment starting from their computer. Fortunately, Jethro is quite skilled at ASCII art. So they model their room with ASCII characters. A space can be moved through. An asterisk * is a wall or furniture that cannot be traversed (no climbing over furniture!). Going up, down, left, right one space takes exactly one step (well assume no diagonal movements for that sake of simplicity). For example, here is a possible model of their room: ************** * A * * * * * * * * *** * * * * ***** * * *** * ************** Assume that (0, 0) is the upper lefthand corner. For the sake of simplicity you can assume the apartment is enclosed in * characters and that the location of Jethros computer has been marked with an A. Jethro is still new to programming and wants to hire you to write the program to label all of the locations in their apartment with the minimum number of steps needed to reach them. To keep with the ASCII art theme youll use the letters A-Z Such that: A is 0 steps B is 1 step C is 2 steps ... Y is 24 steps
  • 2. Z is 25 (or more) steps Heres some example rooms: Example 1: Base room: ***** *A * *** * * * ***** Room after algorithm: ***** *ABC* ***D* *GFE* ***** (We cant pass through the * symbols) Example 2: Base room: ************** * A * * * * * * * * *** * * * * ***** * * *** * ************** Room after algorithm: ************** *BABCDEFGHIJK* *CBCD*FGHIJKL* *DCDE*GHIJKLM* *ED***HIJKLMN* *FEFGHIJKLMNO*
  • 3. *GFGHI*****OP* *HGHIJ***RQPQ* ************** Example 3: Base room: ********************************** * A * ********************************** Room after algorithm: ********************************** *DCBABCDEFGHIJKLMNOPQRSTUVWXYZZZZ* ********************************** (We dont count past Z since Jethro has a pretty small apartment) Example 4: Base room: ******* *A * **** * * * * **** * * * ******* Room after algorithm: ******* *ABCDE* ****EF* * *FG* ****GH* *KJIHI* ******* (Unreachable areas should remain unchanged)Heres some example rooms: Example 1: Base room: ***** *A * *** *
  • 4. * * ***** Room after algorithm: ***** *ABC* ***D* *GFE* ***** (We cant pass through the * symbols) Example 2: Base room: ************** * A * * * * * * * * *** * * * * ***** * * *** * ************** Room after algorithm: ************** *BABCDEFGHIJK* *CBCD*FGHIJKL* *DCDE*GHIJKLM* *ED***HIJKLMN* *FEFGHIJKLMNO* *GFGHI*****OP* *HGHIJ***RQPQ* ************** Example 3: Base room: ********************************** * A * ********************************** Room after algorithm:
  • 5. ********************************** *DCBABCDEFGHIJKLMNOPQRSTUVWXYZZZZ* ********************************** (We dont count past Z since Jethro has a pretty small apartment) Example 4: Base room: ******* *A * **** * * * * **** * * * ******* Room after algorithm: ******* *ABCDE* ****EF* * *FG* ****GH* *KJIHI* ******* (Unreachable areas should remain unchanged) Part 1 - Programming: (15 points) Write a brute force recursive program to solve the problem described above in paintRoom.c. Hint 1: This program will take fewer lines of code than previous one but youll need to think about and test them carefully. For reference, my recP aintRoom only had 10 lines of code in it. Hint 2: From any given space, you need to try to continue moving up, down, left, and right (i.e. 4 recursive calls). Hint 3: Your algorithm can move into a *, but upon recognizing it as an obstacle, it should return from that call. Hint 4: It may help to track the distance traveled so far from the starting A character. Hint 5: Only updating locations that contain a wont be enough. Sometimes youll need to update a location you previously visited and labeled.
  • 6. Hint 6: chars can be treated like small valued integers. In particular, it may be helpful to use operations like + and <= with your chars. PROGRAMS driver.c #include #include #include #include "paintRoom.h" RoomData read2DArray( const char* name ); void print2DArray( RoomData room ); void free2DArray( RoomData room ); /* change the following constants to add/remove some cases for testing */ const int numFiles = 8; const char *defaultFilenames[] = { "room-Small01.txt", "room-Small02.txt", "room- Medium01.txt", "room-Medium02.txt", "room-Long01.txt", "room-Long02.txt", "room- Large01.txt", "room-Large02.txt" }; const bool enableFilenames[] = { true , true , true , true , true , true , true , true }; /* DO NOT MODIFY THIS FILE */ int main( int argc, char *argv[] ) { int i; RoomData room; printName( ); printf("Running default test files: nn"); for( i=0; i #include /* DO NOT MODIFY THIS FILE */ typedef struct RoomData { char **roomArray; /* the 2d char array representing the room shared by Jethro and Cletus */ int numrows; /* the number of rows for the char** roomArray */
  • 7. int numcols; /* the number of columns for the char** roomArray */ } RoomData; void printName( ); void paintRoom( RoomData room ); #endif paintroom.c #include "paintRoom.h" void recPaintRoom( RoomData room, int row, int col, int distanceFromA /*feel free to remove/add any other parameters here*/ ); /*declare any other helper functions here*/ /* printName * input: none * output: none * * Prints name the student who worked on this solution */ void printName( ) { /* TODO : Fill in your name*/ printf("nThis solution was completed by:n"); printf("student namen"); } /* TODO * paintRoom * input: the room to process * output: N/A * * This non-recursive function is called by the driver and it makes the initial call to recursive function recPaintRoom. */ void paintRoom( RoomData room ) { /* Call any other helper functions (a helper function to find the location of 'A' in room may be
  • 8. handy) */ int i; int j; /* Find starting location */ int startRow = -1; int startCol = -1; for( i = 0; i < room.numrows; i++ ){ for( j = 0; j < room.numcols; j++ ) { if( room.roomArray[i][j] == 'A') { /*STOPPING POINT USE FUNCTIONS IN MAKE FILE NOT .roomArray NEXT */ startRow = i; startCol = j; break; } } if( startRow != -1) { break; } } /*Call your recursive function here */ if( startRow != -1) { int currentValue = 0; recPaintRoom( room, startRow, startCol, currentValue); } } /* TODO * recPaintRoom * input: the room to process, the row and column of the current location being explored, the distance traveled from 'A' * output: N/A */ void recPaintRoom( RoomData room, int row, int col, int distanceFromA )
  • 9. { /* debugging output */ printf("Exploring (%d,%d) with label '%c'n", row, col, distanceFromA ); /* Base cases: */ if( row < 0 || row >= room.numrows || col < 0 || col >= room.numcols || room.roomArray[row][col] == '*') { return; } /*Check if current location is an obstacle or already labeled */ if( room.roomArray[row][col] == 'A' || (room.roomArray[row][col] >= 'A' && room.roomArray[row][col] <= 'Z' )){ return; } else /* Update label for current location */ room.roomArray[row][col] = distanceFromA; /* Recursive cases: */ recPaintRoom(room, row - 1, col, distanceFromA + 1); /* Move up */ recPaintRoom(room, row + 1, col, distanceFromA + 1); /* Move down */ recPaintRoom(room, row, col - 1, distanceFromA + 1); /* Move Left */ recPaintRoom(room, row, col + 1, distanceFromA + 1); /* Move Right */ /* Debugging output */ printf("completed rec call with (%d, %d)n", row, col); }