Jump to content

Perfect numbers: Difference between revisions

m
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="ecmascriptwren">var isPerfect = Fn.new { |n|
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="ecmascriptwren">import "./math" for Int
 
var isPerfect = Fn.new { |n|
9,482

edits

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