## Posted By

Scooter on 01/03/09

## Who likes this?

1 person have marked this snippet as a favorite

# Perfect Numbers

/ Published in: ASP

Determine whether the given number is a perfect number.

`<%    ' Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved.    '    ' This work is licensed under the Creative Commons Attribution License. To view    ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or    ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California    ' 94305, USA.     ' Determine whether the given number is a perfect number.    function isPerfect(someNumber)        dim i        dim arrFactors        arrFactors = Array()         ' Only positive integers can be perfect.        if someNumber < 1 then            isPerfect = false            exit function        end if         ' Calculate the factors for the given number.        for i = 1 to someNumber            if someNumber mod i = 0 then                redim preserve arrFactors(UBound(arrFactors) + 1)                arrFactors(UBound(arrFactors)) = i            end if        next         ' A perfect number is a number that is half the sum of all of its positive divisors (including itself).        if someNumber = eval(join(arrFactors, " + ")) / 2 then            isPerfect = true        else            isPerfect = false        end if    end function%>`