SlideShare a Scribd company logo
1 of 6
Download to read offline
CENG140
Section I
C Programming
Spring 2017-2018
Take Home Exam 1
1 Regulations
• Due date: 18 April 2018, Wednesday, 23:55 Not subject to postpone, please do not ask for.
• Submission: Electronically. You will be submitting your program source code written in a
file which you will name as the1.c through the COW. Resubmission is allowed (till the last
moment of the due date), the last will replace the previous.
• Cheating: We have zero tolerance policy for cheating. People involved in cheating will be
punished according to the university regulations.
• Team: There is no teaming up. The take home exam has to be done/turned in individually.
• Newsgroup: You must follow the newsgroup (news.ceng.metu.edu.tr) for discussions and
possible updates on a daily basis.
• Evaluation: Your program will be evaluated automatically using black-box technique so
make sure to obey the specifications. Any program that cannot collect 30 points will be
graded by eye (glass-box evaluation). These eye evaluation are not open to question. They
are final and decisive and are not subject to any objection or questioning.
2 Introduction
In this take home exam, you are expected to find a path for a rabbit in a carrot field. The field
consists of NxN cells (maximum value of N is 100 ), and rabbit gains energy whenever it eats a
carrot. The gain of energy is dependent to some rules, which are given below:
1. If a carrot is level l, it weights 100 × l grams.
2. If a carrot weights γ grams, the gain of energy is 0.4 × γ calories.
3. N will be given to you as input at the beginning (see sample I/O).
4. The rabbit can only move rightward and downward and each move is restricted with one cell.
5. The trip starts from the top-left corner ([0,0]) and ends at the bottom-right corner([N-1,N-1]).
6. The goal is to maximize the energy gained when the rabbit reaches the bottom-right corner.
1
3 Part 1 - Construction of the Field (20+40 points)
At the beginning of the program, the field is empty. Levels of the carrots that vegetate in each cell
will be given to you ordered in time. You are expected to fill the field obeying some rules:
1. There are different types of carrots that are indicated by their level id. In the next section,
you are going to calculate the weights of these carrots based on their level.
2. When a carrot vegetate in a cell (namely, current cell) with level x, if a link is formed among
three or more carrots that have same level id, all of them will be gathered together the current
cell, forming a new carrot with level x+1. Carrots that forming the link will be disappear and
those cells will have the value 0.
3. The link mentioned above can only be formed among neighboring carrots. Neighborhood of
a cell consists of cells at north,east,south and west of it (you don’t need to consider diagonal
relationships).
4. Forming a new carrot with a higher level may trigger another link. You should handle such
cases as well.
5. Empty cells have value 0 and all cells are empty at the beginning. You should not consider
the links between these kind of cells (do not create 1-level carrots using these).
3.1 Example: State of the Field by Time
There is an example of the construction of a 5x5 field in time below. Note that empty cells has
value zero, which is not shown in the figures.
step 1:
empty field
step 2:
1 0 1
1
step 3:
2 2 2
1
2
step 4:
2 2 3
1
2
2
step 5:
1 0 2
1
1 2
2
step 6:
1 1 2
3
step 7:
1 3 0
1
3
step 8:
1 3 1
1
1
3
2
step 9:
1 3 3
1
1
3
1
step 10:
1 4 3
1
1
3
1 1
step 11:
1 3 2
3 2
step 12:
2 4 2
3 2 2
step 13:
3 1 3
3 2 2
3
step 14:
2 2 2
4
step 15:
4 2 3
4
4
step 16:
4 3 4
4
4
4
Here are the explanations for the figure above:
– step 1: all values are 0.
– step 2: 1 0 1 means put a carrot with level 1 into the cell with 0th column, 1st row. Nothing
happens.
– step 3: 2 2 2 means put a carrot with level 2 into the cell with 2nd column, 2nd row. Nothing
happens.
– ...
– step 6: 1 1 2 means put a carrot with level 1 into the cell with 1st column, 2nd row. When we
do that, there a link emerges between three carrots with level 1 and they will form a carrot
level 2 (1+1=2) at the cell [1,2]. Note that the input cell for this step is [1,2]. Since having
a level 2 carrot at this cell also means that forming a line consisting of three level 2 carrots,
they will form a level 3 carrot at this cell. Note that the intermediate steps are not shown and
the carrots that form the links are disappeared except the higher level one (cells that contain
disappeared carrots have value 0 now).
– ...
– step 10: Although we have four level 1 carrots, after placing the current one, they are not
linked. The longest link among these have length 2. Therefore nothing happens.
– step 11: When we put a level 1 carrot into the cell [3,2] as indicated in the input, a link with
length five emerges between level 1 carrots. Since 5>=3, we will form a level 2 carrot at the
current cell (which is [3,2]).
– ...
– step 13: This case is similar to step 5.
– ...
3
– step 16: Nothing happens since we do not consider diagonal neighbors. The longest link has
length two in this case (2<3).
3.2 I/O Format For Construction of the Field
First, you will be given an integer N, indicating the size of the field. Maximum value of N is 100.
Then, (as you already saw in the figure), incoming carrots will be given in form l x y. Here, l is
level of the incoming carrot, x and y are the indices of the cell it will vegetate. You will not be
given indices that are already full. You will be informed with EOF character when there are no
more incoming carrots. For the example above, input will be like this:
5
1 0 1
2 2 2
2 2 3
1 0 2
1 1 2
1 3 0
1 3 1
1 3 3
1 4 3
1 3 2
2 4 2
3 1 3
2 2 2
4 2 3
4 3 4
EOF
Part I has an output, which is the final form of the field printed in a two-dimensional manner.
For the example above, the output should be as below.
0 0 0 0 0
0 0 0 0 0
0 0 4 0 0
0 0 4 0 0
0 0 0 4 0
4 Part II - Finding the Path (40 points)
After constructing the field, we are going to move the rabbit trying to maximizing the energy gain.
The rabbit starts from the cell with index [0,0]. When rabbit goes to a cell, it will gain some energy
based on the level of the carrot in that cell. Calculation will be made as follows:
– If a carrot is level l, it weights 100 × l grams.
– If a carrot weights γ grams, the gain of energy is 0.4 × γ calories.
4
You can easily see that a level 1 carrot gives 40 calories to the rabbit. Do not forget to consider
calories gained from the cell [0,0].
Movement: Rabbit can only move towards south and east. You are expected to find most
beneficial path and output it with the final energy.
4.1 I/O Format For Path
The input of this part is the field that you constructed at the first part of the exam. Therefore, there
will be no additional inputs. Assume the below field is constructed:
0 1 1 2
3 2 3 3
1 1 2 2
4 2 5 0
Final energies for some possible paths are:
– E E E S S S , final energy: 360
– E E S E S S , final energy: 400
Another example:
3 1 1 2 1
3 2 3 3 1
4 4 2 2 3
4 2 5 0 4
3 2 5 1 5
Final energies for some possible paths are:
– E E E S S E S S , final energy: 920
– S S S E E S E E , final energy: 1280
You are expected to print the path with maximum energy similar to format above. If there are
multiple paths giving the maximum energy, printing just one of them is enough. Do not put a dash
in front of the output.
5 Grading and Specifications
– For part I, you need to implement your solution both recursive and iterative manner. Iterative
part will be 20 points and recursive one will be 40 points.
– For part II, implement your solution in recursive manner.
– Do not use static variables.
5
– Do not use global variables.
– Obey I/O format strictly. Otherwise you will not be able to collect points since the exam will
be graded by blackbox technique. In your output, first N lines must belong to output of part
I and the last line must belong to part II. Do not print anything else.
– Since there will be two different implementations for part I, you need to upload two different
files. Both of them must have main function, since they will be executed independently. Both
of them must include the solution for part II.
– Name your files as the1 recursive.c and the1 iterative.c
6

More Related Content

Similar to The1

Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.pptLegesseSamuel
 
Assignment Poblems
Assignment Poblems Assignment Poblems
Assignment Poblems vkabre
 
Quantitativeanalysisfordecisionmaking 13427543542352-phpapp02-120719222252-ph...
Quantitativeanalysisfordecisionmaking 13427543542352-phpapp02-120719222252-ph...Quantitativeanalysisfordecisionmaking 13427543542352-phpapp02-120719222252-ph...
Quantitativeanalysisfordecisionmaking 13427543542352-phpapp02-120719222252-ph...Firas Husseini
 
types of facility layout algorithm
types of facility layout algorithmtypes of facility layout algorithm
types of facility layout algorithmAsIf Fisa
 
Electromania updated
Electromania updatedElectromania updated
Electromania updatedSupriya Gorai
 
Quantitative Analysis For Decision Making
Quantitative Analysis For Decision MakingQuantitative Analysis For Decision Making
Quantitative Analysis For Decision Makingaminsand
 
Cat 2007 paper with key proton training solutions
Cat 2007   paper with key proton training solutions Cat 2007   paper with key proton training solutions
Cat 2007 paper with key proton training solutions Proton Training Solutions
 
Exploratory data analysis v1.0
Exploratory data analysis v1.0Exploratory data analysis v1.0
Exploratory data analysis v1.0Vishy Chandra
 
Simplex Algorithm
Simplex AlgorithmSimplex Algorithm
Simplex AlgorithmAizaz Ahmad
 
Chapter 1 Assignment Problems (DS) (1).pptx
Chapter 1 Assignment Problems (DS) (1).pptxChapter 1 Assignment Problems (DS) (1).pptx
Chapter 1 Assignment Problems (DS) (1).pptxPriyankaLunavat
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3smruti sarangi
 
Deep Learning through Pytorch Exercises
Deep Learning through Pytorch ExercisesDeep Learning through Pytorch Exercises
Deep Learning through Pytorch Exercisesaiaioo
 
Implementing the Perceptron Algorithm for Finding the weights of a Linear Dis...
Implementing the Perceptron Algorithm for Finding the weights of a Linear Dis...Implementing the Perceptron Algorithm for Finding the weights of a Linear Dis...
Implementing the Perceptron Algorithm for Finding the weights of a Linear Dis...Dipesh Shome
 

Similar to The1 (20)

Advanced s and s algorithm.ppt
Advanced s and s algorithm.pptAdvanced s and s algorithm.ppt
Advanced s and s algorithm.ppt
 
UNIT2.pptx
UNIT2.pptxUNIT2.pptx
UNIT2.pptx
 
Assignment Poblems
Assignment Poblems Assignment Poblems
Assignment Poblems
 
Quantitativeanalysisfordecisionmaking 13427543542352-phpapp02-120719222252-ph...
Quantitativeanalysisfordecisionmaking 13427543542352-phpapp02-120719222252-ph...Quantitativeanalysisfordecisionmaking 13427543542352-phpapp02-120719222252-ph...
Quantitativeanalysisfordecisionmaking 13427543542352-phpapp02-120719222252-ph...
 
types of facility layout algorithm
types of facility layout algorithmtypes of facility layout algorithm
types of facility layout algorithm
 
Electromania updated
Electromania updatedElectromania updated
Electromania updated
 
_MODULE1_FINALPAPER.docx
_MODULE1_FINALPAPER.docx_MODULE1_FINALPAPER.docx
_MODULE1_FINALPAPER.docx
 
Quantitative Analysis For Decision Making
Quantitative Analysis For Decision MakingQuantitative Analysis For Decision Making
Quantitative Analysis For Decision Making
 
Qa 2
Qa 2Qa 2
Qa 2
 
Cat 2007 paper with key proton training solutions
Cat 2007   paper with key proton training solutions Cat 2007   paper with key proton training solutions
Cat 2007 paper with key proton training solutions
 
Exploratory data analysis v1.0
Exploratory data analysis v1.0Exploratory data analysis v1.0
Exploratory data analysis v1.0
 
Simplex Algorithm
Simplex AlgorithmSimplex Algorithm
Simplex Algorithm
 
Simplex algorithm
Simplex algorithmSimplex algorithm
Simplex algorithm
 
Chapter 1 Assignment Problems (DS) (1).pptx
Chapter 1 Assignment Problems (DS) (1).pptxChapter 1 Assignment Problems (DS) (1).pptx
Chapter 1 Assignment Problems (DS) (1).pptx
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3
 
Number system
Number systemNumber system
Number system
 
01_memory_manager.pdf
01_memory_manager.pdf01_memory_manager.pdf
01_memory_manager.pdf
 
Deep Learning through Pytorch Exercises
Deep Learning through Pytorch ExercisesDeep Learning through Pytorch Exercises
Deep Learning through Pytorch Exercises
 
Implementing the Perceptron Algorithm for Finding the weights of a Linear Dis...
Implementing the Perceptron Algorithm for Finding the weights of a Linear Dis...Implementing the Perceptron Algorithm for Finding the weights of a Linear Dis...
Implementing the Perceptron Algorithm for Finding the weights of a Linear Dis...
 
Mit6 006 f11_quiz1
Mit6 006 f11_quiz1Mit6 006 f11_quiz1
Mit6 006 f11_quiz1
 

Recently uploaded

VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130Suhani Kapoor
 
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...Suhani Kapoor
 
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiVIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai DouxDubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Douxkojalkojal131
 
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun serviceanilsa9823
 
Call Girls in Kalkaji Delhi 8264348440 call girls ❤️
Call Girls in Kalkaji Delhi 8264348440 call girls ❤️Call Girls in Kalkaji Delhi 8264348440 call girls ❤️
Call Girls in Kalkaji Delhi 8264348440 call girls ❤️soniya singh
 
Peaches App development presentation deck
Peaches App development presentation deckPeaches App development presentation deck
Peaches App development presentation decktbatkhuu1
 
AMBER GRAIN EMBROIDERY | Growing folklore elements | Root-based materials, w...
AMBER GRAIN EMBROIDERY | Growing folklore elements |  Root-based materials, w...AMBER GRAIN EMBROIDERY | Growing folklore elements |  Root-based materials, w...
AMBER GRAIN EMBROIDERY | Growing folklore elements | Root-based materials, w...BarusRa
 
The history of music videos a level presentation
The history of music videos a level presentationThe history of music videos a level presentation
The history of music videos a level presentationamedia6
 
WAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsWAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsCharles Obaleagbon
 
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...Suhani Kapoor
 
Fashion trends before and after covid.pptx
Fashion trends before and after covid.pptxFashion trends before and after covid.pptx
Fashion trends before and after covid.pptxVanshNarang19
 
SD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptxSD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptxjanettecruzeiro1
 
Editorial design Magazine design project.pdf
Editorial design Magazine design project.pdfEditorial design Magazine design project.pdf
Editorial design Magazine design project.pdftbatkhuu1
 
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...babafaisel
 
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...Pooja Nehwal
 
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)amitlee9823
 
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...Call Girls in Nagpur High Profile
 
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service 🧵
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service  🧵CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service  🧵
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service 🧵anilsa9823
 
Punjabi Housewife Call Girls Service Gomti Nagar \ 9548273370 Indian Call Gir...
Punjabi Housewife Call Girls Service Gomti Nagar \ 9548273370 Indian Call Gir...Punjabi Housewife Call Girls Service Gomti Nagar \ 9548273370 Indian Call Gir...
Punjabi Housewife Call Girls Service Gomti Nagar \ 9548273370 Indian Call Gir...nagunakhan
 

Recently uploaded (20)

VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
 
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
VIP College Call Girls Gorakhpur Bhavna 8250192130 Independent Escort Service...
 
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service AmravatiVIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
VIP Call Girl Amravati Aashi 8250192130 Independent Escort Service Amravati
 
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai DouxDubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
 
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
 
Call Girls in Kalkaji Delhi 8264348440 call girls ❤️
Call Girls in Kalkaji Delhi 8264348440 call girls ❤️Call Girls in Kalkaji Delhi 8264348440 call girls ❤️
Call Girls in Kalkaji Delhi 8264348440 call girls ❤️
 
Peaches App development presentation deck
Peaches App development presentation deckPeaches App development presentation deck
Peaches App development presentation deck
 
AMBER GRAIN EMBROIDERY | Growing folklore elements | Root-based materials, w...
AMBER GRAIN EMBROIDERY | Growing folklore elements |  Root-based materials, w...AMBER GRAIN EMBROIDERY | Growing folklore elements |  Root-based materials, w...
AMBER GRAIN EMBROIDERY | Growing folklore elements | Root-based materials, w...
 
The history of music videos a level presentation
The history of music videos a level presentationThe history of music videos a level presentation
The history of music videos a level presentation
 
WAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past QuestionsWAEC Carpentry and Joinery Past Questions
WAEC Carpentry and Joinery Past Questions
 
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
VIP Russian Call Girls in Saharanpur Deepika 8250192130 Independent Escort Se...
 
Fashion trends before and after covid.pptx
Fashion trends before and after covid.pptxFashion trends before and after covid.pptx
Fashion trends before and after covid.pptx
 
SD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptxSD_The MATATAG Curriculum Training Design.pptx
SD_The MATATAG Curriculum Training Design.pptx
 
Editorial design Magazine design project.pdf
Editorial design Magazine design project.pdfEditorial design Magazine design project.pdf
Editorial design Magazine design project.pdf
 
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
 
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...
 
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
 
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service 🧵
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service  🧵CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service  🧵
CALL ON ➥8923113531 🔝Call Girls Kalyanpur Lucknow best Female service 🧵
 
Punjabi Housewife Call Girls Service Gomti Nagar \ 9548273370 Indian Call Gir...
Punjabi Housewife Call Girls Service Gomti Nagar \ 9548273370 Indian Call Gir...Punjabi Housewife Call Girls Service Gomti Nagar \ 9548273370 Indian Call Gir...
Punjabi Housewife Call Girls Service Gomti Nagar \ 9548273370 Indian Call Gir...
 

The1

  • 1. CENG140 Section I C Programming Spring 2017-2018 Take Home Exam 1 1 Regulations • Due date: 18 April 2018, Wednesday, 23:55 Not subject to postpone, please do not ask for. • Submission: Electronically. You will be submitting your program source code written in a file which you will name as the1.c through the COW. Resubmission is allowed (till the last moment of the due date), the last will replace the previous. • Cheating: We have zero tolerance policy for cheating. People involved in cheating will be punished according to the university regulations. • Team: There is no teaming up. The take home exam has to be done/turned in individually. • Newsgroup: You must follow the newsgroup (news.ceng.metu.edu.tr) for discussions and possible updates on a daily basis. • Evaluation: Your program will be evaluated automatically using black-box technique so make sure to obey the specifications. Any program that cannot collect 30 points will be graded by eye (glass-box evaluation). These eye evaluation are not open to question. They are final and decisive and are not subject to any objection or questioning. 2 Introduction In this take home exam, you are expected to find a path for a rabbit in a carrot field. The field consists of NxN cells (maximum value of N is 100 ), and rabbit gains energy whenever it eats a carrot. The gain of energy is dependent to some rules, which are given below: 1. If a carrot is level l, it weights 100 × l grams. 2. If a carrot weights γ grams, the gain of energy is 0.4 × γ calories. 3. N will be given to you as input at the beginning (see sample I/O). 4. The rabbit can only move rightward and downward and each move is restricted with one cell. 5. The trip starts from the top-left corner ([0,0]) and ends at the bottom-right corner([N-1,N-1]). 6. The goal is to maximize the energy gained when the rabbit reaches the bottom-right corner. 1
  • 2. 3 Part 1 - Construction of the Field (20+40 points) At the beginning of the program, the field is empty. Levels of the carrots that vegetate in each cell will be given to you ordered in time. You are expected to fill the field obeying some rules: 1. There are different types of carrots that are indicated by their level id. In the next section, you are going to calculate the weights of these carrots based on their level. 2. When a carrot vegetate in a cell (namely, current cell) with level x, if a link is formed among three or more carrots that have same level id, all of them will be gathered together the current cell, forming a new carrot with level x+1. Carrots that forming the link will be disappear and those cells will have the value 0. 3. The link mentioned above can only be formed among neighboring carrots. Neighborhood of a cell consists of cells at north,east,south and west of it (you don’t need to consider diagonal relationships). 4. Forming a new carrot with a higher level may trigger another link. You should handle such cases as well. 5. Empty cells have value 0 and all cells are empty at the beginning. You should not consider the links between these kind of cells (do not create 1-level carrots using these). 3.1 Example: State of the Field by Time There is an example of the construction of a 5x5 field in time below. Note that empty cells has value zero, which is not shown in the figures. step 1: empty field step 2: 1 0 1 1 step 3: 2 2 2 1 2 step 4: 2 2 3 1 2 2 step 5: 1 0 2 1 1 2 2 step 6: 1 1 2 3 step 7: 1 3 0 1 3 step 8: 1 3 1 1 1 3 2
  • 3. step 9: 1 3 3 1 1 3 1 step 10: 1 4 3 1 1 3 1 1 step 11: 1 3 2 3 2 step 12: 2 4 2 3 2 2 step 13: 3 1 3 3 2 2 3 step 14: 2 2 2 4 step 15: 4 2 3 4 4 step 16: 4 3 4 4 4 4 Here are the explanations for the figure above: – step 1: all values are 0. – step 2: 1 0 1 means put a carrot with level 1 into the cell with 0th column, 1st row. Nothing happens. – step 3: 2 2 2 means put a carrot with level 2 into the cell with 2nd column, 2nd row. Nothing happens. – ... – step 6: 1 1 2 means put a carrot with level 1 into the cell with 1st column, 2nd row. When we do that, there a link emerges between three carrots with level 1 and they will form a carrot level 2 (1+1=2) at the cell [1,2]. Note that the input cell for this step is [1,2]. Since having a level 2 carrot at this cell also means that forming a line consisting of three level 2 carrots, they will form a level 3 carrot at this cell. Note that the intermediate steps are not shown and the carrots that form the links are disappeared except the higher level one (cells that contain disappeared carrots have value 0 now). – ... – step 10: Although we have four level 1 carrots, after placing the current one, they are not linked. The longest link among these have length 2. Therefore nothing happens. – step 11: When we put a level 1 carrot into the cell [3,2] as indicated in the input, a link with length five emerges between level 1 carrots. Since 5>=3, we will form a level 2 carrot at the current cell (which is [3,2]). – ... – step 13: This case is similar to step 5. – ... 3
  • 4. – step 16: Nothing happens since we do not consider diagonal neighbors. The longest link has length two in this case (2<3). 3.2 I/O Format For Construction of the Field First, you will be given an integer N, indicating the size of the field. Maximum value of N is 100. Then, (as you already saw in the figure), incoming carrots will be given in form l x y. Here, l is level of the incoming carrot, x and y are the indices of the cell it will vegetate. You will not be given indices that are already full. You will be informed with EOF character when there are no more incoming carrots. For the example above, input will be like this: 5 1 0 1 2 2 2 2 2 3 1 0 2 1 1 2 1 3 0 1 3 1 1 3 3 1 4 3 1 3 2 2 4 2 3 1 3 2 2 2 4 2 3 4 3 4 EOF Part I has an output, which is the final form of the field printed in a two-dimensional manner. For the example above, the output should be as below. 0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 4 0 0 0 0 0 4 0 4 Part II - Finding the Path (40 points) After constructing the field, we are going to move the rabbit trying to maximizing the energy gain. The rabbit starts from the cell with index [0,0]. When rabbit goes to a cell, it will gain some energy based on the level of the carrot in that cell. Calculation will be made as follows: – If a carrot is level l, it weights 100 × l grams. – If a carrot weights γ grams, the gain of energy is 0.4 × γ calories. 4
  • 5. You can easily see that a level 1 carrot gives 40 calories to the rabbit. Do not forget to consider calories gained from the cell [0,0]. Movement: Rabbit can only move towards south and east. You are expected to find most beneficial path and output it with the final energy. 4.1 I/O Format For Path The input of this part is the field that you constructed at the first part of the exam. Therefore, there will be no additional inputs. Assume the below field is constructed: 0 1 1 2 3 2 3 3 1 1 2 2 4 2 5 0 Final energies for some possible paths are: – E E E S S S , final energy: 360 – E E S E S S , final energy: 400 Another example: 3 1 1 2 1 3 2 3 3 1 4 4 2 2 3 4 2 5 0 4 3 2 5 1 5 Final energies for some possible paths are: – E E E S S E S S , final energy: 920 – S S S E E S E E , final energy: 1280 You are expected to print the path with maximum energy similar to format above. If there are multiple paths giving the maximum energy, printing just one of them is enough. Do not put a dash in front of the output. 5 Grading and Specifications – For part I, you need to implement your solution both recursive and iterative manner. Iterative part will be 20 points and recursive one will be 40 points. – For part II, implement your solution in recursive manner. – Do not use static variables. 5
  • 6. – Do not use global variables. – Obey I/O format strictly. Otherwise you will not be able to collect points since the exam will be graded by blackbox technique. In your output, first N lines must belong to output of part I and the last line must belong to part II. Do not print anything else. – Since there will be two different implementations for part I, you need to upload two different files. Both of them must have main function, since they will be executed independently. Both of them must include the solution for part II. – Name your files as the1 recursive.c and the1 iterative.c 6