/ Published in: ASP
URL: http://reusablecode.blogspot.com/2009/01/perfect-numbers.html
Determine whether the given number is a perfect number.
Expand |
Embed | Plain Text
<% ' 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 %>
You need to login to post a comment.
