Perfect numbers: Difference between revisions
m
→{{header|Wren}}: Minor tidy
m (→cheating: removed unused var) |
m (→{{header|Wren}}: Minor tidy) |
||
Line 4,660:
{{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:
{{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|
|