Question: Please write the program in Haskell. Problem 5. (15 pts. ) Tom found a piece of paper with a coordinate system written on it. There

 Please write the program in Haskell. Problem 5. (15 pts. )

Please write the program in Haskell.

Problem 5. (15 pts. ) Tom found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. The squares are numbered from 1 to n. The opposite corners of the i-th square are (0, 0), (ai, ai). Tom wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. A point belongs to a square, if the point is located either inside the square, or on its boundary. Help Tom find a point that would meet the described limits. Write a function pointIn :: [Int] -> Int -> [Int] whose arguments are the inte- gers list (al,a2....,an) and k (n larger than k). And then return the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them. If there is no answer, print (-1). Expected running results: pointIn [5,1,3,4] 3 *Main> [2,1] YA 5 4 3 2 1 (2.1) O 1 2 3 4 5 Figure 1 : example test case one pointIn [2,4,1] 1 *Main> [4,0] Problem 5. (15 pts. ) Tom found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. The squares are numbered from 1 to n. The opposite corners of the i-th square are (0, 0), (ai, ai). Tom wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly k drawn squares. A point belongs to a square, if the point is located either inside the square, or on its boundary. Help Tom find a point that would meet the described limits. Write a function pointIn :: [Int] -> Int -> [Int] whose arguments are the inte- gers list (al,a2....,an) and k (n larger than k). And then return the coordinates of the point that belongs to exactly k squares. If there are multiple answers, you are allowed to print any of them. If there is no answer, print (-1). Expected running results: pointIn [5,1,3,4] 3 *Main> [2,1] YA 5 4 3 2 1 (2.1) O 1 2 3 4 5 Figure 1 : example test case one pointIn [2,4,1] 1 *Main> [4,0]

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 Accounting Questions!