Answered step by step
Verified Expert Solution
Question
1 Approved Answer
4. Implement function, q4(L, goalX, goalY), that takes a non-empty list, L, of [x,y) pairs, and two goal numbers, and returns tuple (closestXY, XorY) where
4. Implement function, q4(L, goalX, goalY), that takes a non-empty list, L, of [x,y) pairs, and two goal numbers, and returns tuple (closestXY, XorY) where closestXY is the item from L whose x distance from goal X or whose y distance from goalY is the minimum among all distances, and XorY is 'x' if x distance is minimized and 'y' otherwise. You may assume there is a unique answer. Note: You may not use built-in min or max functions. Examples: q4([[4, 4], [10, 10]], 1, 8) should return ([10,10], 'y'). q4 ([[10, 25], [2, 2], [49, 200]], 50, 8) should return ([49,200], 'x')
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