Perfect numbers: Difference between revisions
Content added Content deleted
(→{{header|Python}}: Added a slightly faster variant) |
(→{{header|Python}}: replaced reduce(add) with sum) |
||
Line 2,143:
Or, a little faster (by restricting the search space):
<lang python>from
from math import (sqrt)
Line 2,152 ⟶ 2,151:
# perfect::
def perfect(n):
lows = filter(
Line 2,158 ⟶ 2,157:
xrange(1, 1 + int(sqrt(n)))
)
return (1 < n) and
lows + concatMap(
lambda x: (
lambda y=n / x: [y
)()
)(lows)
) / 2
)
# GENERIC
# concatMap
def concatMap(f):
return lambda xs: (
|