Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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. ) 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
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