Perfect numbers: Difference between revisions
Content added Content deleted
m (→{{header|Python}}: Minor updates for Python3) |
|||
Line 2,325:
Or, a little faster (by restricting the search space):
<lang python>from
from operator import (add)
from math import (sqrt)
Line 2,331 ⟶ 2,332:
# main :: IO ()
def main():
print(
list(filter(perfect, enumFromTo(1)(10000)))
)▼
# perfect :: Int - > Bool
def perfect(n):
lows = list(filter(
lambda x: 0 == (n % x),
))
return (1 < n) and(
n == sum(
Line 2,355 ⟶ 2,358:
# GENERIC --------------------------------
# concatMap :: (a -
def concatMap(f):
for x in xs:
▲ )
a = a + f(x)
return a
return lambda xs: go(xs)
# enumFromTo :: Int -> Int -> [Int]
def enumFromTo(m):
return lambda n: list(range(m, 1 + n))
|