Question
Please use Haskell Q1 Write a function diff that takes two lists as input and returns the difference of the first list with respect to
Please use Haskell
Q1
Write a function diff that takes two lists as input and returns the difference of the first list with respect to the second. The input lists may have duplicate elements. If an element appears in both lists and if the number of duplicate copies of the element is bigger in the first list, then this element should appear in the result as many times as the difference of the number of occurrences in the input lists. The duplicates should not be eliminated in the result. The elements in the resulting list may have arbitrary order. (Hint: You can make use of count function in your solution.)
Examples: > diff [1,2,2,3,3,3,4,4,4,4,5,5,5,5,5,6,6,6,6,6,6] [1,2,3,4,5,7,7] [2,3,3,4,4,4,5,5,5,5,6,6,6,6,6,6] > diff [1,2,2,3,3,3,6,7,4,4,4,4,5,5,5,5,5,6,6] [1,1,2,2,3,3,4,4,5,6,6,6] [3,4,4,5,5,5,5,7] > diff [6,2,2,3,5,3,6,7,4,4,5,4,5,5,4,5,3,1,6] [1,2,2,3,3,3,6,7,4,4,4,4,5,5,5,5,5,6,6] [] > diff "testing my function" "fit " "testing myuncon"
Q2
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 [] []
Q3
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 [] []
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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