Jump to content

Perfect numbers: Difference between revisions

Add Spad code
m (Added translation from Mathematica)
(Add Spad code)
Line 89:
=={{header|Axiom}}==
{{trans|Mathematica}}
Using the interpreter, we can define the function:
Custom function:
<lang Axiom>perfect?(n:Integer):Boolean == reduce(+,divisors n) = 2*n</lang>
Alternatively, using the Spad compiler:
<lang Axiom>)abbrev package TESTP TestPackage
TestPackage() : with
perfect?: Integer -> Boolean
==
add
import IntegerNumberTheoryFunctions
perfect? n == reduce("+",divisors n) = 2*n</lang>
 
Examples (testing 496, testing 128, finding all perfect numbers in 1...10000):
<lang Axiom>perfect? 496
136

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.