Question: Please use Haskell 1. remove_every, remove_every_tail_tail (a) remove_every - 7% Consider the following remove_every function. The function takes an integer n and a list 1
Please use Haskell




1. remove_every, remove_every_tail_tail (a) remove_every - 7% Consider the following remove_every function. The function takes an integer n and a list 1 st and removes the item after every nth element in the list 1 st. If n is greater than the length of the input list, no elements will be removed. If n is , all elements in the list will be deleted. You may assume that n>=0. The below remove_every function will give some type errors/run time exceptions when compiled/run. Identify the problems and fix them. Explain the problems you identified/fixed in a comment. remove_every n[]=[] remove_every n lst = remove_helper n lst n where remove_helper 0(x:xs)k= (remove_helper k xs ) remove_helper n(x:xs)k=x: (remove_helper ( n1)xs) Examples: > remove_every 3 "123a456b789c" "123456789" > remove_every 8[1,2,3,4,5,6,7,8,100] [1,2,3,4,5,6,7,8] > remove_every 9[1,2,3,4,5,6,7,8] [1,2,3,4,5,6,7,8] (b) remove_every_tail - 10% Re-write the remove_every function from part (a) as a tail-recursive function. Name your function remove_every_tail. 2. get_outof_range and count_outof_range (a) get_outof_range 6% Define a function get_outof_range which takes two values, v1 and v2, and a list " xs ", and returns the values in xs which are less than v1 and greater than v2 (exclusive). Your function shouldn't need a recursion but should use a higher order function (map, foldr/foldl, or filter). You may need to define additional helper function(s), which are also not recursive. Examples: >get_outof_range (5)5[10,5,0,1,2,5,10] [10,10] >get_outof_range 46[1,2,3,4,5,6,7,8,9,10] [1,2,3,7,8,9,10] > get_outof_range 'A' 'z' "CptS-355" "-355" Important note about negative integer arguments: In Haskell, the x, where x is a number, is a special form and it is a prefix (and unary) operator negating an integer value. When you pass a negative number as argument function, you may need to enclose the negative number in parenthesis to make sure that unary () is applied to the integer value before it is passed to the function. For example: get_outof_range 55[10,5,0,5,10] will give a type error, but get_outof_range (5)5(10,5,0,5,10] will work (b) count_outof_range 10% Using get_outof_range function you defined in part(a) and without using explicit recursion, define a function count_outof_range which takes two integer values, v1 and v2, and a nested list " xs ", and returns the total number of values in xs which are less than v1 and greater than v2 (exclusive). Your function shouldn't need a recursion but should use higher order function (map, foldr/foldl, or filter). You may need to define additional helper function(s), which are also not recursive. Examples: > count_outof_range (5)5[[10,5,0,1,2,5,10],[4,2,1,3,4,8,5,9,4,10],[5, 6,7,8]] 8 > count_outof_range 'A' 'z' ["Cpt S", "-", "355", ":", "HW2"] 7 > count_outof_range 11[[4,1],[2,1,3,4],[8,0,1,5,9,4]] 10 Assume the "routes" data we used in HW1. 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"]) ] Rewrite the find_routes function in HW1 using higher order functions (map, foldr/foldl, or filter) and without using recursion. Your helper functions should not be recursive as well, but they can use higher order functions. Remember that find routes 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. You can make use of el em function in your solution. The order of the elements in the output can be arbitrary. Examples: > find_routes "Walmart" routes ["Lentil", "Wheat", "Silver"] >ind_routes "Rosauers" routes [] > find_routes "Main" routes ["Lentil", "Silver", "Gray", "Coffee"]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
