Erdős-Nicolas numbers: Difference between revisions

m
syntax highlighting fixup automation
(→‎{{header|Julia}}: slightly more efficient)
m (syntax highlighting fixup automation)
Line 26:
=={{header|ALGOL 68}}==
Builds tables of proper divisor counts and sums and finds the numbers whilst doing it. This means that the numbers are not found in numerical order.
<langsyntaxhighlight lang="algol68">BEGIN # find some Erdos-Nicolas numbers: numbers equal to the sum of their #
# first k proper divisors but k is not the count of all their proper #
# divisors ( so the numbers aren't perfect ) #
Line 51:
OD
OD
END</langsyntaxhighlight>
{{out}}
<pre>
Line 80:
 
=={{header|J}}==
Implementation:<langsyntaxhighlight Jlang="j">divisors=: {{ /:~ ,*/@> { (^ i.@>:)&.>/__ q: y}} ::_:
erdosnicolas=: {{ y e. +/\ _2}. divisors y }}"0</langsyntaxhighlight>Task example:<syntaxhighlight lang J="j"> I.erdosnicolas i.1e7
24 2016 8190 42336 45864 392448 714240 1571328
(,. 1++/\@divisors i. ])@>24 2016 8190 42336 45864 392448 714240 1571328
Line 91:
392448 68
714240 113
1571328 115</langsyntaxhighlight>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="ruby">using Primes
 
function isErdősNicolas_with_k(n)
Line 116:
isEN && println(lpad(n, 8), " equals the sum of its first $k divisors.")
end
</langsyntaxhighlight>{{out}}
<pre>
24 equals the sum of its first 6 divisors.
Line 130:
=={{header|Phix}}==
{{trans|Wren}}
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">erdos_nicolas</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
Line 153:
<span style="color: #000000;">n</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">2</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</langsyntaxhighlight>-->
Aside: The default for factors() is to return neither 1 nor n, though you can change that if you want, ie ",1" -> 1 and n; ",-1" -> 1 but not n.<br>
Output same as Julia
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line>use Prime::Factor;
 
sub is-Erdős-Nicolas ($n) {
Line 172:
exit if ++$count >= 8;
}
}</langsyntaxhighlight>
{{out}}
<pre> 24 == sum of its first 6 divisors
Line 185:
=={{header|Wren}}==
{{libheader|Wren-math}}
<langsyntaxhighlight lang="ecmascript">import "./math" for Int
 
var erdosNicolas = Fn.new { |n|
Line 211:
}
n = n + 2
}</langsyntaxhighlight>
 
{{out}}
10,333

edits