Question
Is anyone able to provide me with codes that will satisfy the examples in the following functions? Please help! Note: Within an elevation map m,
Is anyone able to provide me with codes that will satisfy the examples in the following functions? Please help!
Note: Within an elevation map m, cell [i, j] is a sink if for all adjacent cells [n, m], m[i][j] m[n][m]. With the physical interpretation of an elevation map in mind, water would collect in sinks, since there is no less elevated area in the immediate vicinity for the water to flow to.
1. find local sink(List[List[int]], List[int]) -> List[int]
The first parameter is an elevation map, m, the second parameter is a cell, c, which exists in m. Returns the local sink of c. A local sink of c is the cell which water would flow to if it started at c. Assume if the current location isnt a sink, water will always flow to the adjacent cell with the lowest elevation. You may also assume for the purposes of us testing this function, that all values of m are unique (no two locations have equal elevations).
Examples (note some spacing has been added for human readablity): >>> m = [[ 5,70,71,80], [50, 4,30,90], [60, 3,35,95], [10,72, 2, 1]] >>> find_local_sink(m, [0,0]) [3,3] >>> m = [[ 5,70,71,80], [50, 4, 5,90], [60, 3,35, 2], [ 1,72, 6, 3]] >>> find_local_sink(m, [0,3]) [2,3]
2. can hike to(List[List[int]], List[int], List[int], int) -> bool
The first parameter is an elevation map, m, the second is start cell, s which exists in m, the third is a destination cell, d, which exists in m, and the forth is the amount of available supplies. Under the interpretation that the top of the elevation map is north, you may assume that d is to the south-east of s (this means it could also be directly south, or directly east). The idea 2 is, if a hiker started at s with a given amount of supplies could they reach f if they used the following strategy. The hiker looks at the cell directly to the south and the cell directly to the east, and then travels to the cell with the lower change in elevation. They keep repeating this stratagem until they reach d (return True) or they run out of supplies (return False). Assume to move from one cell to another takes an amount of supplies equal to the change in elevation between the cells. If the change in elevation is the same between going East and going South, the hiker will always go East. Also, the hiker will never choose to travel South, or East of d (they wont overshoot their destination). That is, if d is directly to the East of them, they will only travel East, and if d is directly South, they will only travel South.
Examples (note some spacing has been added for human readablity): >>> m = [[1,4,3], [2,3,5], [5,4,3]] >>> can_hike_to(m, [0,0], [2,2], 4) True >>> can_hike_to(m, [0,0], [0,0], 0) True >>> can_hike_to(m, [0,0], [2,2], 3) False >>> m = [[1, 1,100], [1,100,100], [1, 1, 1]] >>> can_hike_to(m, [0,0], [2,2], 4) False >>> can_hike_to(m, [0,0], [2,2], 202) True
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started