Define a recursive function count

Assignment Help Data Structure & Algorithms
Reference no: EM13850527

Lists & Functions Assignment

This assignment consists of three exercises. You are expected to submit a single file named a5.hs containing
• your name(s) and ID(s) (as comments at the top of the file),
• solutions for all exercises, include type definition for every function/value.
Test your final version of a5.hs files and make sure it compiles and has no syntax or logical errors.

Exercise 1

a) Define a recursive function hasD which takes a non-negative integer n and an integer digit d between 0 and 9 inclusive, and returns True if the base-10 representation of n contains the digit d; False otherwise. For example, hasD 3071 7 should evaluate to True, and hasD 1201 4 to False.

b) Define a recursive function count :: [ Int ] ->

Int ->

Int which,

given a list of non-negative integers intL and an integer digit a between 0 and 9 inclusive, returns the number of integers in intL which contain the digit a (again

when written in base 10). For example, count
to 2, and count [98,4,376] 2 to 0.

[102,41,256] 2 should evaluate

c) Re-write the function from point b define using list comprehension-call it countC.

Exercise 2

a) Write a recursive function takeOut::Int->[Int]->[Int] so that

takeOut m

xs removes all multiples of m from xs.

b) Re-write the function from point a using list comptrehension-call it takeOutB.

c) Write a recursive function called count3r that takes a list of triples of Ints as a parameter. The result should be the number of triples for which the last element is the sum of the first two elements. For example:
count3r [(6,-8,-2),( 2,4,6),(8,7,1),(4,5,9)] should return 3

and count3r

[(-1,3,1), (1,5,7)] should return 0

d) Re-write the function from point c) using list comprehension;call it count3L

Exercise 3 Write a Haskell script that will display some information about data stored in a file called DVDdata.hs The file DVDdata.hs contains a list of DVD movies and for each movie it contains its ID number, its title, whether it is available



(yes, no) and if it is overdue, how many days it is overdue. according to the movie ID values.
Here is a possible DVDdata.hs file:

The list is sorted

673_de.png

Your script should print a table with a) proper headings and
b) containing the following information for each DVD:

i. ii. iii. iv)

ID number title availability
if overdue - the required payment . The payment for overdue DVDs is computed by multiplying the number of overdue days by penaltyPerDay.

c) a footer containing the total number of available DVDs.
d) The list of DVDs should be now sorted on the title of the DVDs.
e) The output should be produced when the function printable (see picture below) is invoked at the prompt.

The output obtained from the above file should be like this:

628_d3.png

Be aware that the content of the file DVDdata.hs can be changed (for example more
DVDs can be included in the list), but the format of the information will be preserved.


Submit your solution electronically.

Important:
1. You can define and use other functions in order to solve a problem that asks you to define a function to perform a specific task.
2. Run your final version of a5.hs file on the computer labs and make sure it has no errors. Please note that if we cannot run your a5.hs script you will get 0 marks.

Reference no: EM13850527

Questions Cloud

What diversity policies did they adopt : Write one long paragraph about diversity based on one of the employers onDiversityInc's list. For example, what made that company unique, what diversity policies did they adopt, and comments about the leadership of that company
Purpose and concepts of analytical procedures : Describe the purpose and concepts of analytical procedures based on the applicable auditing standards (ASA) in Australia. From the period of global financial crisis during 2007-2010
Brands are machines for delivering quality earnings : "Brands are machines for delivering quality earnings at high margins". A good answer would begin by explaining the concept of the brand and outlining reasons why people are prepared to pay a premium for strongly branded products and services
Discuss how the system shall recover from attacks : Discuss how the system shall recover from attacks,
Define a recursive function count : Define a recursive function count
Explain the discrepancy : Explain the discrepancy
Write a c program for addition : Write a C Program for addition
What are the main types of strategic alliances : What are the main types of strategic alliances? Compare and contrast them. Describe the basic steps for a successful e-commerce strategy
Explain demand schedule and demand curve : Find mathematically and graphically the Equilibrium price and Quantity - Explain demand schedule and demand curve, and how they are related? Why does the demand curve slope downward?

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Define how to building a binary search tree

Three of these operations (all but add) must visit every node in the tree. One of these must use preorder traversal, one must use inorder traversal, and one must use postorder traversal.

  Give an algorithm that takes a sequence of points

Give an algorithm that takes a sequence of points in the plane (x1, y1), (x2, y2), ...., (xn, yn) and an integer k as input and returns the best piecewise linear function f consisting of at most k pieces that minimizes the sum squared error.

  List the inputs any processes calculations and outputs

Your goal is to solve the following simple programming exercise. You have been contracted by a local antique store to design an algorithm determining the total purchases and sales tax. List the inputs, any processes, calculations, and outputs

  Show the brute-force attack against single des

Your task is to show that breaking the scheme is approximately as difficult as a brute-force attack against single DES.

  How many different undirected graphs are there with v vertix

Graph enumeration: How many different undirected graphs are there with V vertices and E edges (and no parallel edges)? Assume the graph is represented in adjacency-list form

  Create own flowchart for website

Use any program with which you are comfortable to create your own flowchart for your website. Libre Writer or Microsoft Word are good programs to create a flowchart, but there are others

  Describes the steps required to perform the task specified

Write an algorithm in structured English (pseudocode) that describes the steps required to perform the task specified. Some examples of pseudocode can be found athttp://www.unf.edu/~broggio/cop2221/2221pseu.htm

  Find running time of heap sort input sorted-ascending order

Determine the running time of Heap Sort if input is sorted in ascending order. Determine the running time of Heap Sort if input is sorted in descending order.

  Deliverable is to design an algorithm

Deliverable is to design an algorithm for a function that accepts an integer array as an argument and returns the total of values in the array. this is algorithm

  Give an algorithm that returns the position

Give an algorithm that returns true if a string contains properly nested and balanced parentheses, and false if otherwise. Hint: At no time while scanning a legal string from left to right will you have encountered more right parentheses than left..

  Write an algorithm for computing total flight time

Write an algorithm for computing total flight time and the horizontal distance traveled by the cannon ball for the problem discussed in class?

  Describe an algorithm that takes as input a list of n

Describe an algorithm that takes as input a list of n distinct integers and finds the location of the largest even integer in the list or returns 0 if there are no even integers in the list.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd