Question: Question 3 : Complete a Path Shaanan wants to make sure the grass on his lawn is of equal length. It means that each time
Question : Complete a Path
Shaanan wants to make sure the grass on his lawn is of equal length. It means that each time Shaanan mows, he goes through a path covering the entire backyard with his lawnmower. Also, given he has to mow the entire lawn, he really wants to avoid any repetition ie mowing the same piece of grass twice
He comes up with two strategies to mow the lawn that will satisfy his requirement above:
Strategy Back and Forth Path: start at the top left corner and go straight to the right. Every time he reaches the edge of the backyard, make a Uturn and continue mowing.
Strategy Spiral Path: start at the top left corner and go clockwise through a spiral path until he reaches the centre with no more land to cover.
Your Task
Write a function completepathdimension pathtype
Input:
dimension: A element tuple rowdim, coldim signalling the dimension of the backyard described in Q
pathtype: A str with value of either "backandforth" or "spiral", signalling the type of the path.
Output: The path as described above, depending on pathtype. The format of the path is the same as in Q The returned path should contain every coordinate in the backyard, without duplication.
Assumptions you can make:
The inputs are wellformatted with the correct type.
The dimension tuple contains two int with positive values.
Example calls:
printcompletepath "backandforth"
printcompletepath "spiral"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
