(a) elemAll 10% Write a Haskell function elemAll that takes two lists as input and returns...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
(a) elemAll 10% Write a Haskell function elemAll that takes two lists as input and returns True if all elements in the first list appear in the second list. It returns False otherwise. Note that both input lists should have the same type. Your function shouldn't need a recursion but should use higher order functions (map, foldr/foldl, or filter). Your helper functions should not be recursive as well, but they can use higher order functions. Note: You can use the built-in "elem" function in your solution. Examples: > elemAll [3,5,7,10] [1,2,3,4,5,6,7,8,9,10] True > elemAll [3,5,10] [1,2,3,4,5,6,7,8,9] False > elemAll ["Bishop", "TerreView","Walmart"] ["Chinook", "Orchard","Valley", "Maple", "Aspen", "TerreView", "Clay", "Dismores", "Martin", "Bishop", "Walmart", "Porchlight" , "Campus"] True > elemAll ["Bishop", "TerreView"] ["TransferStation", "Porchlight", "Stadium", "Bishop", "Walmart", "Shopco", "RockeyWay"] False (b) stopsAt 10% Pullman Transit offers many bus routes in Pullman. Assume we store the bus stops for the bus routes in a list of tuples. The first element of each tuple is the bus route and the second element is the list of stops for that route (see below for an example). buses = [("Wheat", ["Chinook", "Orchard", "Valley", "Maple", "Aspen", "TerreView", "Clay", "Dismores", "Martin", "Bishop", "Walmart", "Porchlight", "Campus"]), ("Silver", ["TransferStation", "Porchlight", "Stadium", "Bishop", "Walmart", "Shopco", "RockeyWay"]), ("Blue", ["TransferStation", "State", "Larry", "TerreView","Grand", "TacoBell", "Chinook", "Library"]), ("Gray", ["TransferStation", "Wawawai", "Main", "Sunnyside", "Crestview", "CityHall", "Stadium", "Colorado"]) ] Write a Haskell function stopsat, that takes a list of bus stop names 'stops' and the bus route data 'buses' (similar to the above) as input and returns the bus route names that stop at each and every stop in 'stops'. Your function shouldn't need a recursion but should use higher order functions (map, foldr/foldl, or filter). Your helper functions should not be recursive as well, but they can use higher order functions. The order of the route names in the output can be arbitrary. Hint: You can use the "elemAll" function you defined in part(a) in your solution. Examples: > stopsAt ["Bishop", "TerreView", "Walmart"] buses ["Wheat"] >stopsAt ["Bishop", "Walmart"] buses ["Wheat", "Silver"] >p2b_test3 = stopsAt ["Transfer Station", "State", "Main"] buses [ ] (a) elemAll 10% Write a Haskell function elemAll that takes two lists as input and returns True if all elements in the first list appear in the second list. It returns False otherwise. Note that both input lists should have the same type. Your function shouldn't need a recursion but should use higher order functions (map, foldr/foldl, or filter). Your helper functions should not be recursive as well, but they can use higher order functions. Note: You can use the built-in "elem" function in your solution. Examples: > elemAll [3,5,7,10] [1,2,3,4,5,6,7,8,9,10] True > elemAll [3,5,10] [1,2,3,4,5,6,7,8,9] False > elemAll ["Bishop", "TerreView","Walmart"] ["Chinook", "Orchard","Valley", "Maple", "Aspen", "TerreView", "Clay", "Dismores", "Martin", "Bishop", "Walmart", "Porchlight" , "Campus"] True > elemAll ["Bishop", "TerreView"] ["TransferStation", "Porchlight", "Stadium", "Bishop", "Walmart", "Shopco", "RockeyWay"] False (b) stopsAt 10% Pullman Transit offers many bus routes in Pullman. Assume we store the bus stops for the bus routes in a list of tuples. The first element of each tuple is the bus route and the second element is the list of stops for that route (see below for an example). buses = [("Wheat", ["Chinook", "Orchard", "Valley", "Maple", "Aspen", "TerreView", "Clay", "Dismores", "Martin", "Bishop", "Walmart", "Porchlight", "Campus"]), ("Silver", ["TransferStation", "Porchlight", "Stadium", "Bishop", "Walmart", "Shopco", "RockeyWay"]), ("Blue", ["TransferStation", "State", "Larry", "TerreView","Grand", "TacoBell", "Chinook", "Library"]), ("Gray", ["TransferStation", "Wawawai", "Main", "Sunnyside", "Crestview", "CityHall", "Stadium", "Colorado"]) ] Write a Haskell function stopsat, that takes a list of bus stop names 'stops' and the bus route data 'buses' (similar to the above) as input and returns the bus route names that stop at each and every stop in 'stops'. Your function shouldn't need a recursion but should use higher order functions (map, foldr/foldl, or filter). Your helper functions should not be recursive as well, but they can use higher order functions. The order of the route names in the output can be arbitrary. Hint: You can use the "elemAll" function you defined in part(a) in your solution. Examples: > stopsAt ["Bishop", "TerreView", "Walmart"] buses ["Wheat"] >stopsAt ["Bishop", "Walmart"] buses ["Wheat", "Silver"] >p2b_test3 = stopsAt ["Transfer Station", "State", "Main"] buses [ ]
Expert Answer:
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Posted Date:
Students also viewed these programming questions
-
write the answer on Haskell Notation The US currency is the dollar. 1 dollar = 100 cents. In US currency, there are several types of coins, each of which is given a name, namely quarter (1 quarter =...
-
Haskell Corporation reported the following operating results for two consecutive years. _______________________2019 2018 Percentage Change Sales ........................$550,000.....................
-
Please Identify relevant ethical issues presented by consulting AICPA Code of Professional Conduct. In your memo response, please site specific sections from the Code of Conduct that you used to...
-
Ned and Nelly Norbert, both aged 35, have three small children. Nancy aged 10, Nadia aged 8, and Nadine aged 3. The Norberts want to ensure that they have adequate resources in place to complete...
-
The demand for MICHTECs products is related to the state of the economy. If the economy is expanding next year (an above-normal growth in GNP), the company expects sales to be $90 million. If there...
-
What is the output of the following code segment? t = 7; if(t > 7) { System.out.print("AAA"); System.out.print("BBB"); } a. AAA b. BBB c. AAABBB d. Nothing
-
Do people who are interested in environmental issues visit museums more often than people who are not? The General Social Survey asked 990 people how interested they were in environmental issues, and...
-
When Teris outside basis in the TMF Partnership is $80,000, the partnership distributes to her $30,000 cash, an account receivable (fair market value of $60,000, inside basis to the partnership of...
-
You work as the management accountant for Grabby's Medical Solutions Company (GMSco). They currently sell digital medical systems (systems) to the health care industry for $16,000 each. The systems...
-
George Pharmacy is a pharmaceutical salesman who has been very successful at his job in the last few years. Unfortunately, his family life has not been very happy. Three years ago, his only child,...
-
Beginning balances of UPM Companys accounts as of January 1, 2016 as given below: Beg Balance Account Title Debit Credit Cash 142300 Accounts Receivable 48500 Supplies 18000 Prepaid Insurance 0...
-
i) Information security is the process by which an organization protects and secures its systems, including media, and facilities that process and maintain information vital to its operations....
-
In the management of Health Records and Information Management Profession there are critical aspects and membership that ensured harmony and quality services in Kenya. Describe the functions of the...
-
Loop: LD DADDI SD DADDI DSUB BNEZ Use the following code fragment: R1,0 (R2) R1, R1, #1 R1,0, (R2) ;load R1 from address 0+R2 ;RI=R1+1 store R1 at address 0+R2 R2-R2+4 ;R4-R3-R2 ;branch to Loop if...
-
The pressure inside an airplane is 1.00 atm (1.01 x 105 N/m2). What is the magnitude of the net force exerted on a 1.10 m x 2.30 m rectangular cabin door at a height of 36,000 ft if the outside...
-
Segmentation and Buying Decisions You are the Marketing Manager for the Microsoft Surface tablet computer. Your computer is sold to both end consumers and to corporate IT departments. Describe the...
-
Given the expression below, what can be said about g ? R(a,b, c, d,e, f, g) a, b->c a, b->g a->d d->e
-
If (x) 0 on the interval [a, b], the definite integral gives the exact area under the curve between x = a and x = b.
-
Suppose we have a hash set that uses the standard mod hash function shown in the chapter and uses linear probing for collision resolution. The starting hash table length is 11, and the table does not...
-
The java.util package has an interface called ListIterator that extends the Iterator interface and includes additional methods that are specific to iterating through the elements of lists forward or...
-
Write a method called shift that rearranges the elements of a list of integers by moving to the end of the list all values that are in oddnumbered positions and otherwise preserving list order. For...
-
Clausius-Clayperon equation is applicable to (a) Solid-vapour (b) Solid-liquid (c) Liquid-vapour (d) All of these.
-
The reaction \(A(\mathrm{l}) ightarrow R(\mathrm{~g})\) is allowed to reach equilibrium condition in an autoclave. At equilibrium there are two phases - one a pure liquid phase of \(A\) and the other...
-
The equilibrium constant for the reaction \(\mathrm{N}_{2}(\mathrm{~g})+3 \mathrm{H}_{2}(\mathrm{~g}) ightarrow 2 \mathrm{NH}_{3}\) is 0.1084 . Under the same conditions, the equilibrium constant for...
Study smarter with the SolutionInn App