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 3: 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 (i.e., mowing the same piece of grass twice).
He comes up with two strategies to mow the lawn that will satisfy his requirement above:
Strategy 1- 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 U-turn and continue mowing.
Strategy 2- 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 complete_path(dimension, path_type).
Input:
dimension: A 2-element tuple (row_dim, col_dim) signalling the dimension of the backyard (described in Q2).
path_type: A str with value of either "back_and_forth" or "spiral", signalling the type of the path.
Output: The path as described above, depending on path_type. The format of the path is the same as in Q2. The returned path should contain every coordinate in the backyard, without duplication.
Assumptions you can make:
The inputs are well-formatted with the correct type.
The dimension tuple contains two int with positive values.
Example calls:
>>> print(complete_path((3,4), "back_and_forth"))
[(0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2),(2,3)]
>>> print(complete_path((3,4), "spiral"))
[(0,0),(0,1),(0,2),(0,3),(1,3),(2,3),(2,2),(2,1),(2,0),(1,0),(1,1),(1,2)]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!