Chowla numbers: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
Thundergnat (talk | contribs) m (Automated syntax highlighting fixup (second round - minor fixes)) |
||
Line 74: | Line 74: | ||
:* the OEIS entry for [http://oeis.org/A048050 A48050 Chowla's function]. |
:* the OEIS entry for [http://oeis.org/A048050 A48050 Chowla's function]. |
||
<br><br> |
<br><br> |
||
=={{header|11l}}== |
=={{header|11l}}== |
||
{{trans|C}} |
{{trans|C}} |
||
<syntaxhighlight lang=11l>F chowla(n) |
<syntaxhighlight lang="11l">F chowla(n) |
||
V sum = 0 |
V sum = 0 |
||
V i = 2 |
V i = 2 |
||
Line 169: | Line 168: | ||
There are 5 perfect numbers < 350000000 |
There are 5 perfect numbers < 350000000 |
||
</pre> |
</pre> |
||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
{{trans|C}} |
{{trans|C}} |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="ada">with Ada.Text_IO; |
||
procedure Chowla_Numbers is |
procedure Chowla_Numbers is |
||
Line 293: | Line 291: | ||
33550336 is a perfect number |
33550336 is a perfect number |
||
There are 5 perfect numbers < 350000000</pre> |
There are 5 perfect numbers < 350000000</pre> |
||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
{{Trans|C}} |
{{Trans|C}} |
||
<syntaxhighlight lang=algol68>BEGIN # find some Chowla numbers ( Chowla n = sum of divisors of n exclusing n and 1 ) # |
<syntaxhighlight lang="algol68">BEGIN # find some Chowla numbers ( Chowla n = sum of divisors of n exclusing n and 1 ) # |
||
# returs the Chowla number of n # |
# returs the Chowla number of n # |
||
PROC chowla = ( INT n )INT: |
PROC chowla = ( INT n )INT: |
||
Line 386: | Line 383: | ||
There are 5 perfect numbers < 350000000 |
There are 5 perfect numbers < 350000000 |
||
</pre> |
</pre> |
||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
<syntaxhighlight lang=rebol>chowla: function [n]-> sum remove remove factors n 1 n |
<syntaxhighlight lang="rebol">chowla: function [n]-> sum remove remove factors n 1 n |
||
countPrimesUpTo: function [limit][ |
countPrimesUpTo: function [limit][ |
||
count: 1 |
count: 1 |
||
Line 465: | Line 461: | ||
8128 |
8128 |
||
33550336</pre> |
33550336</pre> |
||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="awk"> |
||
# syntax: GAWK -f CHOWLA_NUMBERS.AWK |
# syntax: GAWK -f CHOWLA_NUMBERS.AWK |
||
# converted from Go |
# converted from Go |
||
Line 595: | Line 590: | ||
There are 5 perfect numbers <= 35,000,000 |
There are 5 perfect numbers <= 35,000,000 |
||
</pre> |
</pre> |
||
=={{header|C}}== |
=={{header|C}}== |
||
<syntaxhighlight lang=c>#include <stdio.h> |
<syntaxhighlight lang="c">#include <stdio.h> |
||
unsigned chowla(const unsigned n) { |
unsigned chowla(const unsigned n) { |
||
Line 679: | Line 673: | ||
33550336 is a perfect number |
33550336 is a perfect number |
||
There are 5 perfect numbers < 350000000</pre> |
There are 5 perfect numbers < 350000000</pre> |
||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
<syntaxhighlight lang=csharp>using System; |
<syntaxhighlight lang="csharp">using System; |
||
namespace chowla_cs |
namespace chowla_cs |
||
Line 792: | Line 785: | ||
There are 5 perfect numbers <= 35,000,000 |
There are 5 perfect numbers <= 35,000,000 |
||
</pre> |
</pre> |
||
=={{header|C++}}== |
=={{header|C++}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
<syntaxhighlight lang=cpp>#include <vector> |
<syntaxhighlight lang="cpp">#include <vector> |
||
#include <iostream> |
#include <iostream> |
||
Line 902: | Line 894: | ||
33,550,336 is a number that is perfect |
33,550,336 is a number that is perfect |
||
There are 5 perfect numbers <= 35,000,000</pre> |
There are 5 perfect numbers <= 35,000,000</pre> |
||
=={{header|CLU}}== |
=={{header|CLU}}== |
||
<syntaxhighlight lang=clu>% Chowla's function |
<syntaxhighlight lang="clu">% Chowla's function |
||
chowla = proc (n: int) returns (int) |
chowla = proc (n: int) returns (int) |
||
sum: int := 0 |
sum: int := 0 |
||
Line 1,026: | Line 1,017: | ||
=={{header|Cowgol}}== |
=={{header|Cowgol}}== |
||
{{trans|C}} |
{{trans|C}} |
||
<syntaxhighlight lang=cowgol>include "cowgol.coh"; |
<syntaxhighlight lang="cowgol">include "cowgol.coh"; |
||
sub chowla(n: uint32): (sum: uint32) is |
sub chowla(n: uint32): (sum: uint32) is |
||
Line 1,143: | Line 1,134: | ||
33550336 is a perfect number. |
33550336 is a perfect number. |
||
There are 5 perfect numbers < 35000000</pre> |
There are 5 perfect numbers < 35000000</pre> |
||
=={{header|D}}== |
=={{header|D}}== |
||
{{trans|C#}} |
{{trans|C#}} |
||
<syntaxhighlight lang=d>import std.stdio; |
<syntaxhighlight lang="d">import std.stdio; |
||
int chowla(int n) { |
int chowla(int n) { |
||
Line 1,259: | Line 1,249: | ||
33550336 is a number that is perfect |
33550336 is a number that is perfect |
||
There are 5 perfect numbers <= 35,000,000</pre> |
There are 5 perfect numbers <= 35,000,000</pre> |
||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
See [[#Pascal]]. |
See [[#Pascal]]. |
||
Line 1,266: | Line 1,255: | ||
{{trans|C#}} |
{{trans|C#}} |
||
<syntaxhighlight lang=dyalect>func chowla(n) { |
<syntaxhighlight lang="dyalect">func chowla(n) { |
||
var sum = 0 |
var sum = 0 |
||
var i = 2 |
var i = 2 |
||
Line 1,395: | Line 1,384: | ||
33550336 is a number that is perfect |
33550336 is a number that is perfect |
||
There are 5 perfect numbers <= 35,000,000</pre> |
There are 5 perfect numbers <= 35,000,000</pre> |
||
=={{header|EasyLang}}== |
=={{header|EasyLang}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
<syntaxhighlight lang=text>func chowla n . sum . |
<syntaxhighlight lang="text">func chowla n . sum . |
||
sum = 0 |
sum = 0 |
||
i = 2 |
i = 2 |
||
Line 1,543: | Line 1,531: | ||
There are 5 perfect mumbers up to 35,000,000 |
There are 5 perfect mumbers up to 35,000,000 |
||
</pre> |
</pre> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
<syntaxhighlight lang=factor>USING: formatting fry grouping.extras io kernel math |
<syntaxhighlight lang="factor">USING: formatting fry grouping.extras io kernel math |
||
math.primes.factors math.ranges math.statistics sequences |
math.primes.factors math.ranges math.statistics sequences |
||
tools.memory.private ; |
tools.memory.private ; |
||
Line 1,626: | Line 1,613: | ||
33,550,336 is perfect |
33,550,336 is perfect |
||
</pre> |
</pre> |
||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
{{trans|Visual Basic}} |
{{trans|Visual Basic}} |
||
<syntaxhighlight lang=freebasic> |
<syntaxhighlight lang="freebasic"> |
||
' Chowla_numbers |
' Chowla_numbers |
||
Line 1,773: | Line 1,759: | ||
Pulsa una tecla para salir |
Pulsa una tecla para salir |
||
</pre> |
</pre> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
<syntaxhighlight lang=go>package main |
<syntaxhighlight lang="go">package main |
||
import "fmt" |
import "fmt" |
||
Line 1,910: | Line 1,895: | ||
There are 5 perfect numbers <= 35,000,000 |
There are 5 perfect numbers <= 35,000,000 |
||
</pre> |
</pre> |
||
=={{header|Groovy}}== |
=={{header|Groovy}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
<syntaxhighlight lang=groovy>class Chowla { |
<syntaxhighlight lang="groovy">class Chowla { |
||
static int chowla(int n) { |
static int chowla(int n) { |
||
if (n < 1) throw new RuntimeException("argument must be a positive integer") |
if (n < 1) throw new RuntimeException("argument must be a positive integer") |
||
Line 2,033: | Line 2,017: | ||
Uses arithmoi Library: https://hackage.haskell.org/package/arithmoi-0.11.0.0 |
Uses arithmoi Library: https://hackage.haskell.org/package/arithmoi-0.11.0.0 |
||
compiled with "-O2 -threaded -rtsopts"<br/> |
compiled with "-O2 -threaded -rtsopts"<br/> |
||
<syntaxhighlight lang=haskell>import Control.Concurrent (setNumCapabilities) |
<syntaxhighlight lang="haskell">import Control.Concurrent (setNumCapabilities) |
||
import Control.Monad.Par (runPar, get, spawnP) |
import Control.Monad.Par (runPar, get, spawnP) |
||
import Control.Monad (join, (>=>)) |
import Control.Monad (join, (>=>)) |
||
Line 2,147: | Line 2,131: | ||
33,550,336 is a perfect number. |
33,550,336 is a perfect number. |
||
There are 5 perfect numbers < 35,000,000</pre> |
There are 5 perfect numbers < 35,000,000</pre> |
||
=={{header|J}}== |
=={{header|J}}== |
||
'''Solution:''' |
'''Solution:''' |
||
<syntaxhighlight lang=j>chowla=: >: -~ >:@#.~/.~&.q: NB. sum of factors - (n + 1) |
<syntaxhighlight lang="j">chowla=: >: -~ >:@#.~/.~&.q: NB. sum of factors - (n + 1) |
||
intsbelow=: (2 }. i.)"0 |
intsbelow=: (2 }. i.)"0 |
||
Line 2,156: | Line 2,139: | ||
findPerfectsbelow=: (#~ <: = chowla)@intsbelow</syntaxhighlight> |
findPerfectsbelow=: (#~ <: = chowla)@intsbelow</syntaxhighlight> |
||
'''Tasks:''' |
'''Tasks:''' |
||
<syntaxhighlight lang=j> (] ,. chowla) >: i. 37 NB. chowla numbers 1-37 |
<syntaxhighlight lang="j"> (] ,. chowla) >: i. 37 NB. chowla numbers 1-37 |
||
1 0 |
1 0 |
||
2 0 |
2 0 |
||
Line 2,198: | Line 2,181: | ||
findPerfectsbelow 35000000 |
findPerfectsbelow 35000000 |
||
6 28 496 8128 33550336</syntaxhighlight> |
6 28 496 8128 33550336</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{trans|C}} |
{{trans|C}} |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="java"> |
||
public class Chowla { |
public class Chowla { |
||
Line 2,342: | Line 2,324: | ||
There are 5 perfect numbers < 35,000,000 |
There are 5 perfect numbers < 35,000,000 |
||
</pre> |
</pre> |
||
=={{header|jq}}== |
=={{header|jq}}== |
||
{{works with|jq}} |
{{works with|jq}} |
||
Line 2,348: | Line 2,329: | ||
The "brute-force" computation of the perfect number beyond 8,128 took many hours. |
The "brute-force" computation of the perfect number beyond 8,128 took many hours. |
||
<syntaxhighlight lang=jq>def add(stream): reduce stream as $x (0; . + $x); |
<syntaxhighlight lang="jq">def add(stream): reduce stream as $x (0; . + $x); |
||
# input should be an integer |
# input should be an integer |
||
Line 2,477: | Line 2,458: | ||
33,550,336 |
33,550,336 |
||
</pre> |
</pre> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
<syntaxhighlight lang=julia>using Primes, Formatting |
<syntaxhighlight lang="julia">using Primes, Formatting |
||
function chowla(n) |
function chowla(n) |
||
Line 2,573: | Line 2,552: | ||
The count of perfect numbers up to 35,000,000 is 5. |
The count of perfect numbers up to 35,000,000 is 5. |
||
</pre> |
</pre> |
||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
<syntaxhighlight lang=scala>// Version 1.3.21 |
<syntaxhighlight lang="scala">// Version 1.3.21 |
||
fun chowla(n: Int): Int { |
fun chowla(n: Int): Int { |
||
Line 2,642: | Line 2,620: | ||
Same as Go example. |
Same as Go example. |
||
</pre> |
</pre> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
{{trans|D}} |
{{trans|D}} |
||
<syntaxhighlight lang=lua>function chowla(n) |
<syntaxhighlight lang="lua">function chowla(n) |
||
local sum = 0 |
local sum = 0 |
||
local i = 2 |
local i = 2 |
||
Line 2,773: | Line 2,750: | ||
33550336 is a number that is perfect |
33550336 is a number that is perfect |
||
There are 5 perfect numbers <= 35,000,000</pre> |
There are 5 perfect numbers <= 35,000,000</pre> |
||
=={{header|MAD}}== |
=={{header|MAD}}== |
||
{{trans|C}} |
{{trans|C}} |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="mad"> NORMAL MODE IS INTEGER |
||
INTERNAL FUNCTION(N) |
INTERNAL FUNCTION(N) |
||
Line 2,877: | Line 2,853: | ||
33550336 IS A PERFECT NUMBER. |
33550336 IS A PERFECT NUMBER. |
||
THERE ARE 5 PERFECT NUMBERS BELOW 35000000</pre> |
THERE ARE 5 PERFECT NUMBERS BELOW 35000000</pre> |
||
=={{header|Maple}}== |
=={{header|Maple}}== |
||
{{incorrect|Maple| <br><br> The output for Chowla(1) is incorrect. <br><br> }} |
{{incorrect|Maple| <br><br> The output for Chowla(1) is incorrect. <br><br> }} |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="maple">ChowlaFunction := n -> NumberTheory:-SumOfDivisors(n) - n - 1; |
||
PrintChowla := proc(n::posint) local i; |
PrintChowla := proc(n::posint) local i; |
||
Line 2,958: | Line 2,933: | ||
664579 |
664579 |
||
[6, 28, 496, 8128, 33550336]</pre> |
[6, 28, 496, 8128, 33550336]</pre> |
||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="mathematica">ClearAll[Chowla] |
||
Chowla[0 | 1] := 0 |
Chowla[0 | 1] := 0 |
||
Chowla[n_] := DivisorSigma[1, n] - 1 - n |
Chowla[n_] := DivisorSigma[1, n] - 1 - n |
||
Line 2,980: | Line 2,954: | ||
664579 |
664579 |
||
{1, 6, 28, 496, 8128, 33550336}</pre> |
{1, 6, 28, 496, 8128, 33550336}</pre> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{trans|C}} |
{{trans|C}} |
||
<syntaxhighlight lang=nim>import strformat |
<syntaxhighlight lang="nim">import strformat |
||
import strutils |
import strutils |
||
Line 3,078: | Line 3,051: | ||
There are 5 perfect numbers < 350,000,000 |
There are 5 perfect numbers < 350,000,000 |
||
</pre> |
</pre> |
||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
{{works with|Free Pascal}} |
{{works with|Free Pascal}} |
||
Line 3,085: | Line 3,056: | ||
{{trans|Go}} but not using a sieve, cause a sieve doesn't need precalculated small primes.<BR> |
{{trans|Go}} but not using a sieve, cause a sieve doesn't need precalculated small primes.<BR> |
||
So runtime is as bad as trial division. |
So runtime is as bad as trial division. |
||
<syntaxhighlight lang=pascal>program Chowla_numbers; |
<syntaxhighlight lang="pascal">program Chowla_numbers; |
||
{$IFDEF FPC} |
{$IFDEF FPC} |
||
Line 3,246: | Line 3,217: | ||
real 1m54,534s |
real 1m54,534s |
||
</pre> |
</pre> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{libheader|ntheory}} |
{{libheader|ntheory}} |
||
<syntaxhighlight lang=perl>use strict; |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
use ntheory 'divisor_sum'; |
use ntheory 'divisor_sum'; |
||
Line 3,333: | Line 3,303: | ||
There are 5 perfect numbers up to 35,000,000: 6 28 496 8,128 33,550,336</pre> |
There are 5 perfect numbers up to 35,000,000: 6 28 496 8,128 33,550,336</pre> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--<syntaxhighlight lang= |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">function</span> <span style="color: #000000;">chowla</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> |
<span style="color: #008080;">function</span> <span style="color: #000000;">chowla</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #008080;">return</span> <span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">factors</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">))</span> |
<span style="color: #008080;">return</span> <span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">factors</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">))</span> |
||
Line 3,410: | Line 3,379: | ||
become 4s and 90s respectively, without finding anything else. Obviously 1.4e11 and 2.4e18 |
become 4s and 90s respectively, without finding anything else. Obviously 1.4e11 and 2.4e18 |
||
were picked to minimise the run times. |
were picked to minimise the run times. |
||
=={{header|Picat}}== |
=={{header|Picat}}== |
||
{{trans|Prolog}} |
{{trans|Prolog}} |
||
{{works with|Picat}} |
{{works with|Picat}} |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="picat"> |
||
table |
table |
||
chowla(1) = 0. |
chowla(1) = 0. |
||
Line 3,507: | Line 3,475: | ||
There are 5 perfect numbers less than 35000000. |
There are 5 perfect numbers less than 35000000. |
||
</pre> |
</pre> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="picolisp">(de accu1 (Var Key) |
||
(if (assoc Key (val Var)) |
(if (assoc Key (val Var)) |
||
(con @ (inc (cdr @))) |
(con @ (inc (cdr @))) |
||
Line 3,621: | Line 3,588: | ||
(6 28 496 8128 33550336) |
(6 28 496 8128 33550336) |
||
</pre> |
</pre> |
||
=={{header|PowerBASIC}}== |
=={{header|PowerBASIC}}== |
||
Line 3,627: | Line 3,593: | ||
{{trans|Visual Basic .NET}} |
{{trans|Visual Basic .NET}} |
||
<syntaxhighlight lang=powerbasic>#COMPILE EXE |
<syntaxhighlight lang="powerbasic">#COMPILE EXE |
||
#DIM ALL |
#DIM ALL |
||
#COMPILER PBCC 6 |
#COMPILER PBCC 6 |
||
Line 3,779: | Line 3,745: | ||
There are 8 perfect numbers <= 2,305,843,009,213,693,950 |
There are 8 perfect numbers <= 2,305,843,009,213,693,950 |
||
press any key to exit program</pre> |
press any key to exit program</pre> |
||
=={{header|Prolog}}== |
=={{header|Prolog}}== |
||
{{works with|SWI Prolog}} |
{{works with|SWI Prolog}} |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="prolog"> |
||
chowla(1, 0). |
chowla(1, 0). |
||
chowla(2, 0). |
chowla(2, 0). |
||
Line 3,900: | Line 3,865: | ||
There are 5 perfect numbers < 35,000,000. |
There are 5 perfect numbers < 35,000,000. |
||
</pre> |
</pre> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
Uses [https://www.python.org/dev/peps/pep-0515/ underscores to separate digits] in numbers, and th [https://www.sympy.org/en/index.htm sympy library] to aid calculations. |
Uses [https://www.python.org/dev/peps/pep-0515/ underscores to separate digits] in numbers, and th [https://www.sympy.org/en/index.htm sympy library] to aid calculations. |
||
<syntaxhighlight lang=python># https://docs.sympy.org/latest/modules/ntheory.html#sympy.ntheory.factor_.divisors |
<syntaxhighlight lang="python"># https://docs.sympy.org/latest/modules/ntheory.html#sympy.ntheory.factor_.divisors |
||
from sympy import divisors |
from sympy import divisors |
||
Line 4,001: | Line 3,965: | ||
* Splitting one function for the jit compiler to digest. |
* Splitting one function for the jit compiler to digest. |
||
<syntaxhighlight lang=python>from numba import jit |
<syntaxhighlight lang="python">from numba import jit |
||
# https://docs.sympy.org/latest/modules/ntheory.html#sympy.ntheory.factor_.divisors |
# https://docs.sympy.org/latest/modules/ntheory.html#sympy.ntheory.factor_.divisors |
||
Line 4,040: | Line 4,004: | ||
Speedup - not much, subjectively... |
Speedup - not much, subjectively... |
||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
<syntaxhighlight lang=racket>#lang racket |
<syntaxhighlight lang="racket">#lang racket |
||
(require racket/fixnum) |
(require racket/fixnum) |
||
Line 4,135: | Line 4,098: | ||
Primes < 10000000: 664579 |
Primes < 10000000: 664579 |
||
There are 5 perfect numbers <= 35000000: (6 28 496 8128 33550336)</pre> |
There are 5 perfect numbers <= 35000000: (6 28 496 8128 33550336)</pre> |
||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
(formerly Perl 6) |
(formerly Perl 6) |
||
Line 4,144: | Line 4,106: | ||
(For a more reasonable test, reduce the orders-of-magnitude range in the "Primes count" line from 2..7 to 2..5) |
(For a more reasonable test, reduce the orders-of-magnitude range in the "Primes count" line from 2..7 to 2..5) |
||
<syntaxhighlight lang=raku line>sub comma { $^i.flip.comb(3).join(',').flip } |
<syntaxhighlight lang="raku" line>sub comma { $^i.flip.comb(3).join(',').flip } |
||
sub schnitzel (\Radda, \radDA = 0) { |
sub schnitzel (\Radda, \radDA = 0) { |
||
Line 4,226: | Line 4,188: | ||
33,550,336 |
33,550,336 |
||
</pre> |
</pre> |
||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<syntaxhighlight lang=rexx>/*REXX program computes/displays chowla numbers (and may count primes & perfect numbers.*/ |
<syntaxhighlight lang="rexx">/*REXX program computes/displays chowla numbers (and may count primes & perfect numbers.*/ |
||
parse arg LO HI . /*obtain optional arguments from the CL*/ |
parse arg LO HI . /*obtain optional arguments from the CL*/ |
||
if LO=='' | LO=="," then LO= 1 /*Not specified? Then use the default.*/ |
if LO=='' | LO=="," then LO= 1 /*Not specified? Then use the default.*/ |
||
Line 4,333: | Line 4,294: | ||
33,550,336 is a perfect number. |
33,550,336 is a perfect number. |
||
</pre> |
</pre> |
||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
{{trans|C}} |
{{trans|C}} |
||
<syntaxhighlight lang=ruby>def chowla(n) |
<syntaxhighlight lang="ruby">def chowla(n) |
||
sum = 0 |
sum = 0 |
||
i = 2 |
i = 2 |
||
Line 4,439: | Line 4,399: | ||
33550336 is a perfect number |
33550336 is a perfect number |
||
There are 5 perfect numbers < 350000000</pre> |
There are 5 perfect numbers < 350000000</pre> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
This solution uses a lazily-evaluated iterator to find and sum the divisors of a number, and speeds up the large searches using parallel vectors. |
This solution uses a lazily-evaluated iterator to find and sum the divisors of a number, and speeds up the large searches using parallel vectors. |
||
<syntaxhighlight lang=scala>object ChowlaNumbers { |
<syntaxhighlight lang="scala">object ChowlaNumbers { |
||
def main(args: Array[String]): Unit = { |
def main(args: Array[String]): Unit = { |
||
println("Chowla Numbers...") |
println("Chowla Numbers...") |
||
Line 4,512: | Line 4,471: | ||
4: 8,128 |
4: 8,128 |
||
5: 33,550,336</pre> |
5: 33,550,336</pre> |
||
=={{header|Swift}}== |
=={{header|Swift}}== |
||
Uses Grand Central Dispatch to perform concurrent prime counting and perfect number searching |
Uses Grand Central Dispatch to perform concurrent prime counting and perfect number searching |
||
<syntaxhighlight lang=swift>import Foundation |
<syntaxhighlight lang="swift">import Foundation |
||
@inlinable |
@inlinable |
||
Line 4,652: | Line 4,610: | ||
8128 is a perfect number |
8128 is a perfect number |
||
33550336 is a perfect number</pre> |
33550336 is a perfect number</pre> |
||
=={{header|Visual Basic}}== |
=={{header|Visual Basic}}== |
||
{{works with|Visual Basic|6}} |
{{works with|Visual Basic|6}} |
||
{{trans|Visual Basic .NET}} |
{{trans|Visual Basic .NET}} |
||
<syntaxhighlight lang=vb>Option Explicit |
<syntaxhighlight lang="vb">Option Explicit |
||
Private Declare Function AllocConsole Lib "kernel32.dll" () As Long |
Private Declare Function AllocConsole Lib "kernel32.dll" () As Long |
||
Line 4,818: | Line 4,775: | ||
There are 5 perfect numbers <= 35.000.000 |
There are 5 perfect numbers <= 35.000.000 |
||
press enter to quit program.</pre> |
press enter to quit program.</pre> |
||
=={{header|Visual Basic .NET}}== |
=={{header|Visual Basic .NET}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
<syntaxhighlight lang=vbnet>Imports System |
<syntaxhighlight lang="vbnet">Imports System |
||
Module Program |
Module Program |
||
Line 4,923: | Line 4,879: | ||
===More Cowbell=== |
===More Cowbell=== |
||
{{libheader|System.Numerics}}One can get a little further, but that 8th perfect number takes nearly a minute to verify. The 9th takes longer than I have patience. If you care to see the 9th and 10th perfect numbers, change the 31 to 61 or 89 where indicated by the comment. |
{{libheader|System.Numerics}}One can get a little further, but that 8th perfect number takes nearly a minute to verify. The 9th takes longer than I have patience. If you care to see the 9th and 10th perfect numbers, change the 31 to 61 or 89 where indicated by the comment. |
||
<syntaxhighlight lang=vbnet>Imports System.Numerics |
<syntaxhighlight lang="vbnet">Imports System.Numerics |
||
Module Program |
Module Program |
||
Line 5,035: | Line 4,991: | ||
2,305,843,008,139,952,128 is a number that is perfect |
2,305,843,008,139,952,128 is a number that is perfect |
||
There are 8 perfect numbers <= 25,000,000,000,000,000,000</pre> |
There are 8 perfect numbers <= 25,000,000,000,000,000,000</pre> |
||
=={{header|Vlang}}== |
=={{header|Vlang}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
<syntaxhighlight lang=vlang>fn chowla(n int) int { |
<syntaxhighlight lang="vlang">fn chowla(n int) int { |
||
if n < 1 { |
if n < 1 { |
||
panic("argument must be a positive integer") |
panic("argument must be a positive integer") |
||
Line 5,160: | Line 5,115: | ||
There are 5 perfect numbers <= 35,000,000 |
There are 5 perfect numbers <= 35,000,000 |
||
</pre> |
</pre> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
{{libheader|Wren-math}} |
{{libheader|Wren-math}} |
||
<syntaxhighlight lang=ecmascript>import "./fmt" for Fmt |
<syntaxhighlight lang="ecmascript">import "./fmt" for Fmt |
||
import "./math" for Int, Nums |
import "./math" for Int, Nums |
||
Line 5,253: | Line 5,207: | ||
There are 5 perfect numbers <= 35,000,000 |
There are 5 perfect numbers <= 35,000,000 |
||
</pre> |
</pre> |
||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="xpl0">func Chowla(N); \Return sum of divisors |
||
int N, Div, Sum, Quot; |
int N, Div, Sum, Quot; |
||
[Div:= 2; Sum:= 0; |
[Div:= 2; Sum:= 0; |
||
Line 5,344: | Line 5,297: | ||
33550336 |
33550336 |
||
</pre> |
</pre> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
<syntaxhighlight lang=zkl>fcn chowla(n){ |
<syntaxhighlight lang="zkl">fcn chowla(n){ |
||
if(n<1) |
if(n<1) |
||
throw(Exception.ValueError("Chowla function argument must be positive")); |
throw(Exception.ValueError("Chowla function argument must be positive")); |
||
Line 5,371: | Line 5,323: | ||
c |
c |
||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
<syntaxhighlight lang=zkl>fcn testChowla{ |
<syntaxhighlight lang="zkl">fcn testChowla{ |
||
println("The first 37 Chowla numbers:\n", |
println("The first 37 Chowla numbers:\n", |
||
[1..37].apply(chowla).concat(" ","[","]"), "\n"); |
[1..37].apply(chowla).concat(" ","[","]"), "\n"); |