Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you are going to write a Haskell function named factors to find all proper factors of a positive Integer. Given a positive

In this assignment, you are going to write a Haskell function named factors to find all proper factors of a
positive Integer.
Given a positive Integer value n, a proper factor of n is defined to be an Integer value i between 1 to n
(exclusively) such that n is divisible by i; that is, the remainder of dividing n by i is zero (0). Note that although
n is divisible by both 1 and n, they are not proper factors of n.
The function factors has the following type signature:
factors :: Integer [Integer]
That is, it takes an Integer as its only parameter and returns a list of Integers. The elements in the list are
all proper factors of the parameter, and they must be all unique and in ascending order.
Here are some examples:
factors ,
154,176,224,308,352,616,1232
factors ,
factors 9676[2,4,41,59,82,118,164,236,2419,4838]
factors 1179[3,9,131,393]
factors 4639[]
Note that the output for the last example is an empty list since 4,639 is a prime number and it has no proper
factor.
Download the three files "CSC207a3.hs","CSC207a3Tester.hs", and "CSC207a3TestData.hs" from
Canvas and save them in the same folder. The last two files are the tester program and the test data file,
respectively. Do not modify these two files. The first file is the file you will work on. Note that you cannot
rename this file and you cannot change the name of the function (otherwise the tester will not be able to pick
up your implementation). However, you can change the names of the parameters if you like. Also note that
the first line is required for the tester to locate your code so do not modify it.
The file "CSC207a3. hs" contains a dummy implementation of the function that always returns a singleton list
with the input parameter as its only element (since a value cannot be a proper factor of itself, it is always
incorrect). The contents of the file "CSC207a3.hs" is listed here for your reference: factors :: Integer ->[Integer]
factors n =[n]
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions

Question

=+b) Compute the x2 statistic.

Answered: 1 week ago