6 lines
385 B
Text
6 lines
385 B
Text
|| The function which takes a number and returns a list of its factors (including one but excluding itself)
|
|
|| can be written
|
|
factors n = { a <- 1.. n/2; n rem a = 0 }
|
|
|| If we define a perfect number as one which is equal to the sum of its factors (for example 6 = 3 + 2 + 1 is perfect)
|
|
|| we can write the list of all perfect numbers as
|
|
perfects = { n <- 1... ; n = sum(factors n) }
|