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

  Explain algorithm which gives initial infection of computer

Explain an O(m+n) algorithm which, given an initial infection of a computer Ca at time t determines for each other computer the earliest time at which it can become infected.

  Creating an automated checkout program

A local department store employee you to create an automated checkout program to expedite customers in a hurry. The checkout line can only allow 5-products for any one purchase.

  Algorithm of prim

NFR4: Prim's algorithm should be used to find a minimum spanning tree (see FR6). NFR5: Dijkstra's  algorithm should be used to find a shortest path between two stations (FR7).

  Finding time taken to send packet from source to destination

Think about sending a document of F bytes over a path of Q links. Each link transmits at R bps. The network is lightly loaded so that there are no queuing delays.

  Compute the memory required by array

Compute the memory required by array and linked list to store exactly 10 nodes. Note that the linked list requires head pointer too.

  Advanced systems analysis and designtasks 1 - produce a

advanced systems analysis and designtasks 1 - produce a system specification indicating functional and non-functional

  Design algorithm to read a file of employee records

Design an algorithm and souce code C++ that will read a file of employee records and produce a weekly report of gross earnings for those employees.

  Part 1 - report write a 2000-word report that describes a

part 1 - report write a 2000-word report that describes a suitable methodology from the literature for the purpose of

  Database design activities

Assume Ray wishes to start a DVD rental program at his stores that he plans to call Henry's DVD Club. He refers to each of his consumers as members.

  What is the logarithm base-2 of zero? of one

What is the logarithm base-2 of zero? of one?

  Linear-time algorithm to find odd-length cycle in graph

Give a linear-time algorithm to find an odd-length cycle in a directed graph. You may not suppose that graph is strongly connected.

  Returns true if a string contains properly nested

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..

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