Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

College Accounting A Practical Approach

Authors: Jeffrey Slater, Debra Good

14th Canadian Edition

0135222419, 978-0135222416

More Books

Students also viewed these Accounting questions

Question

In your own words, summarize the primary objectives of unions.

Answered: 1 week ago