Perfect numbers: Difference between revisions
m
→{{header|EasyLang}}
m (→cheating: removed unused var) |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 1,556:
=={{header|EasyLang}}==
<syntaxhighlight
while i < n
if n mod i = 0
sum += i
.
i += 1
.
return 1
.
return 0
.
for i = 2 to 10000
if perf i = 1
.
.
</syntaxhighlight>
{{out}}
<pre>
6 28 496 8128
</pre>
=={{header|Eiffel}}==
Line 1,625 ⟶ 1,634:
=={{header|Elena}}==
ELENA
<syntaxhighlight lang="elena">import system'routines;
import system'math;
Line 1,633 ⟶ 1,642:
{
isPerfect()
= new Range(1, self - 1).selectBy::(n => (self.mod
}
public program()
{
for(int n := 1
{
if(n.isPerfect())
Line 4,660 ⟶ 4,669:
{{trans|D}}
Restricted to the first four perfect numbers as the fifth one is very slow to emerge.
<syntaxhighlight lang="
if (n <= 2) return false
var tot = 1
Line 4,693 ⟶ 4,702:
{{libheader|Wren-math}}
This makes use of the fact that all known perfect numbers are of the form <big> (2<sup>''n''</sup> - 1) × 2<sup>''n'' - 1</sup></big> where <big> (2<sup>''n''</sup> - 1)</big> is prime and finds the first seven perfect numbers instantly. The numbers are too big after that to be represented accurately by Wren.
<syntaxhighlight lang="
var isPerfect = Fn.new { |n|
|