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

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

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