Question: 4 . A positive integer is perfect if it equals the sum of all of its factors, excluding the number itself. Use a list comprehension
A positive integer is perfect if it equals the sum of all of its factors, excluding the number itself. Use a list comprehension and the following function factors: factors:: Int Int factors n x x n n mod x to define a function perfects:: Int Int that returns the list of all perfect numbers up to a given limit For example in GHCi: perfects
Hint: define an auxiliary function that is perfect:: Int Bool which returns True if the given Int is perfect and False otherwise. Then use isperfect as a guard in a list comprehension to filter out all of the nonperfect integers, ie to keep only the perfect integers.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
