Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use Haskell code and give test code 1.(a) make_sparse Write a function make_sparse which takes a compressed vector value (represented as a Haskell list

Please use Haskell code and give test code

1.(a) make_sparse Write a function make_sparse which takes a compressed vector value (represented as a Haskell list of tuples) and returns the equivalent sparse vector (including all 0 values). Examples:

> make_sparse [(3,30),(10,100),(11,110)] [0,0,0,30,0,0,0,0,0,0,100,110] > make_sparse [(1,1),(2,2),(4,4),(6,6),(9,9)] [0,1,2,0,4,0,6,0,0,9] > make_sparse [(20,1)] [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] > make_sparse [] []

1.(b) compress

Write a function compress which takes a sparse vector value (represented as a Haskell list) and returns the equivalent compressed values as a list of tuples. Examples: > compress [0,0,0,30,0,0,0,0,0,0,100,110] [(3,30),(10,100),(11,110)] > compress [0,1,2,0,4,0,6,0,0,9] [(1,1),(2,2),(4,4),(6,6),(9,9)] > compress [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] [(20,1)] > compress [] []

2. added_sums Write a function added_sums that takes a list of numbers and returns a list including the cumulative partial sums of these numbers. (Hint: Define and use a helper function that takes a list and a number holding the accumulated sum. ) Examples: > added_sums [1,2,3,4,5,6,7,8,9,10] [1,3,6,10,15,21,28,36,45,55] > added_sums [0,-2,3,4,-4,-1,2] [0,-2,1,5,1,0,2] > added_sums [] []

3. find_routes Pullman Transit offers many bus routes in Pullman. Assume that they maintain the bus stops for their routes as 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).

routes = [("Lentil",["Chinook", "Orchard", "Valley", "Emerald", "Providence", "Stadium", "Main", "Arbor", "Sunnyside", "Fountain", "Crestview", "Wheatland", "Walmart", "Bishop", "Derby", "Dilke"]), ("Wheat",["Chinook", "Orchard", "Valley", "Maple", "Aspen", "TerreView", "Clay", "Dismores", "Martin", "Bishop", "Walmart", "PorchLight", "Campus"]), ("Silver",["TransferStation", "PorchLight", "Stadium", "Bishop", "Walmart", "Outlet", "RockeyWay", "Main"]), ("Blue", ["TransferStation", "State", "Larry", "TerreView", "Grand", "TacoBell", "Chinook", "Library"]), ("Gray", ["TransferStation", "Wawawai", "Main", "Sunnyside", "Crestview", "CityHall", "Stadium", "Colorado"]), ("Coffee",["TransferStation", "Grand", "Main", "Visitor","Stadium", "Spark", "CUB"])] Assume that you are creating an application for Pullman Transit. You would like to write an Haskell function find_routes that takes the list of bus routes and a stop name, and returns the list of the bus routes which stop at the given bus stop. (Hint: You can make use of elem function in your solution.) Examples: > find_routes "Walmart" routes_test ["Lentil","Wheat","Silver"] > find_routes "Rosauers" routes_test [] > find_routes "Main" routes_test ["Lentil","Silver","Gray","Coffee"]

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

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions