Zumkeller numbers: Difference between revisions
Content added Content deleted
Tag: Rollback |
(lang->syntaxhighlight test.) |
||
Line 37: | Line 37: | ||
{{trans|D}} |
{{trans|D}} |
||
< |
<syntaxhighlight lang="11l">F getDivisors(n) |
||
V divs = [1, n] |
V divs = [1, n] |
||
V i = 2 |
V i = 2 |
||
Line 112: | Line 112: | ||
I count % 8 == 0 |
I count % 8 == 0 |
||
print() |
print() |
||
i += 2</ |
i += 2</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 145: | Line 145: | ||
=={{header|AArch64 Assembly}}== |
=={{header|AArch64 Assembly}}== |
||
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |
||
< |
<syntaxhighlight lang="AArch64 Assembly"> |
||
/* ARM assembly AARCH64 Raspberry PI 3B */ |
/* ARM assembly AARCH64 Raspberry PI 3B */ |
||
/* program zumkellex641.s */ |
/* program zumkellex641.s */ |
||
Line 633: | Line 633: | ||
/* for this file see task include a file in language AArch64 assembly */ |
/* for this file see task include a file in language AArch64 assembly */ |
||
.include "../includeARM64.inc" |
.include "../includeARM64.inc" |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{Output:}} |
{{Output:}} |
||
<pre> |
<pre> |
||
Line 661: | Line 661: | ||
On my machine, this takes about 0.28 seconds to perform the two main searches and a further 107 to do the stretch task. However, the latter time can be dramatically reduced to 1.7 seconds with the cheat of knowing beforehand that the first 200 or so odd Zumkellers not ending with 5 are divisible by 63. The "abundant number" optimisation's now used with odd numbers, but the cheat-free running time was only two to three seconds longer without it. |
On my machine, this takes about 0.28 seconds to perform the two main searches and a further 107 to do the stretch task. However, the latter time can be dramatically reduced to 1.7 seconds with the cheat of knowing beforehand that the first 200 or so odd Zumkellers not ending with 5 are divisible by 63. The "abundant number" optimisation's now used with odd numbers, but the cheat-free running time was only two to three seconds longer without it. |
||
< |
<syntaxhighlight lang="applescript">-- Sum n's proper divisors. |
||
on aliquotSum(n) |
on aliquotSum(n) |
||
if (n < 2) then return 0 |
if (n < 2) then return 0 |
||
Line 819: | Line 819: | ||
local cheating |
local cheating |
||
set cheating to false |
set cheating to false |
||
doTask(cheating)</ |
doTask(cheating)</syntaxhighlight> |
||
{{output}} |
{{output}} |
||
< |
<syntaxhighlight lang="applescript">"1st 220 Zumkeller numbers: |
||
6 12 20 24 28 30 40 42 48 54 56 60 66 70 78 80 84 88 90 96 |
6 12 20 24 28 30 40 42 48 54 56 60 66 70 78 80 84 88 90 96 |
||
102 104 108 112 114 120 126 132 138 140 150 156 160 168 174 176 180 186 192 198 |
102 104 108 112 114 120 126 132 138 140 150 156 160 168 174 176 180 186 192 198 |
||
Line 845: | Line 845: | ||
351351 459459 513513 567567 621621 671517 729729 742203 783783 793611 |
351351 459459 513513 567567 621621 671517 729729 742203 783783 793611 |
||
812889 837837 891891 908523 960687 999999 1024947 1054053 1072071 1073709 |
812889 837837 891891 908523 960687 999999 1024947 1054053 1072071 1073709 |
||
1095633 1108107 1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377"</ |
1095633 1108107 1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377"</syntaxhighlight> |
||
=={{header|ARM Assembly}}== |
=={{header|ARM Assembly}}== |
||
{{works with|as|Raspberry Pi}} |
{{works with|as|Raspberry Pi}} |
||
< |
<syntaxhighlight lang="ARM Assembly"> |
||
/* ARM assembly Raspberry PI */ |
/* ARM assembly Raspberry PI */ |
||
/* program zumkeller4.s */ |
/* program zumkeller4.s */ |
||
Line 1,527: | Line 1,527: | ||
/***************************************************/ |
/***************************************************/ |
||
.include "../affichage.inc" |
.include "../affichage.inc" |
||
</syntaxhighlight> |
|||
</lang> |
|||
<pre> |
<pre> |
||
Program start |
Program start |
||
Line 1,560: | Line 1,560: | ||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="csharp">using System; |
||
using System.Collections.Generic; |
using System.Collections.Generic; |
||
using System.Linq; |
using System.Linq; |
||
Line 1,655: | Line 1,655: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>The first 220 Zumkeller numbers are: |
<pre>The first 220 Zumkeller numbers are: |
||
Line 1,684: | Line 1,684: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang="cpp>#include <iostream"> |
||
#include <cmath> |
#include <cmath> |
||
#include <vector> |
#include <vector> |
||
Line 1,826: | Line 1,826: | ||
// if we get here it ain't no zum |
// if we get here it ain't no zum |
||
return false; |
return false; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,871: | Line 1,871: | ||
=={{header|D}}== |
=={{header|D}}== |
||
{{trans|C#}} |
{{trans|C#}} |
||
< |
<syntaxhighlight lang="d">import std.algorithm; |
||
import std.stdio; |
import std.stdio; |
||
Line 1,961: | Line 1,961: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>The first 220 Zumkeller numbers are: |
<pre>The first 220 Zumkeller numbers are: |
||
Line 1,991: | Line 1,991: | ||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
This task uses [https://rosettacode.org/wiki/Sum_of_divisors#F.23] |
This task uses [https://rosettacode.org/wiki/Sum_of_divisors#F.23] |
||
< |
<syntaxhighlight lang="fsharp"> |
||
// Zumkeller numbers: Nigel Galloway. May 16th., 2021 |
// Zumkeller numbers: Nigel Galloway. May 16th., 2021 |
||
let rec fG n g=match g with h::_ when h>=n->h=n |h::t->fG n t || fG(n-h) t |_->false |
let rec fG n g=match g with h::_ when h>=n->h=n |h::t->fG n t || fG(n-h) t |_->false |
||
Line 2,002: | Line 2,002: | ||
Seq.initInfinite((*)2>>(+)1)|>Seq.map(fun n->(n,sod n))|>Seq.filter(fun(n,g)->fN n g)|>Seq.take 40|>Seq.iter(fun(n,_)->printf "%d " n); printfn "\n" |
Seq.initInfinite((*)2>>(+)1)|>Seq.map(fun n->(n,sod n))|>Seq.filter(fun(n,g)->fN n g)|>Seq.take 40|>Seq.iter(fun(n,_)->printf "%d " n); printfn "\n" |
||
Seq.initInfinite((*)2>>(+)1)|>Seq.filter(fun n->n%10<>5)|>Seq.map(fun n->(n,sod n))|>Seq.filter(fun(n,g)->fN n g)|>Seq.take 40|>Seq.iter(fun(n,_)->printf "%d " n); printfn "\n" |
Seq.initInfinite((*)2>>(+)1)|>Seq.filter(fun n->n%10<>5)|>Seq.map(fun n->(n,sod n))|>Seq.filter(fun(n,g)->fN n g)|>Seq.take 40|>Seq.iter(fun(n,_)->printf "%d " n); printfn "\n" |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,013: | Line 2,013: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2019-10-06}} |
{{works with|Factor|0.99 2019-10-06}} |
||
< |
<syntaxhighlight lang="factor">USING: combinators grouping io kernel lists lists.lazy math |
||
math.primes.factors memoize prettyprint sequences ; |
math.primes.factors memoize prettyprint sequences ; |
||
Line 2,054: | Line 2,054: | ||
"First 40 odd Zumkeller numbers not ending with 5:" print |
"First 40 odd Zumkeller numbers not ending with 5:" print |
||
40 odd-zumkellers-no-5 8 show</ |
40 odd-zumkellers-no-5 8 show</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,085: | Line 2,085: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">package main |
||
import "fmt" |
import "fmt" |
||
Line 2,175: | Line 2,175: | ||
} |
} |
||
fmt.Println() |
fmt.Println() |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,208: | Line 2,208: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
{{Trans|Python}} |
{{Trans|Python}} |
||
< |
<syntaxhighlight lang="haskell">import Data.List (group, sort) |
||
import Data.List.Split (chunksOf) |
import Data.List.Split (chunksOf) |
||
import Data.Numbers.Primes (primeFactors) |
import Data.Numbers.Primes (primeFactors) |
||
Line 2,280: | Line 2,280: | ||
justifyRight :: Int -> Char -> String -> String |
justifyRight :: Int -> Char -> String -> String |
||
justifyRight n c = (drop . length) <*> (replicate n c <>)</ |
justifyRight n c = (drop . length) <*> (replicate n c <>)</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>First 220 Zumkeller numbers: |
<pre>First 220 Zumkeller numbers: |
||
Line 2,313: | Line 2,313: | ||
=={{header|J}}== |
=={{header|J}}== |
||
Implementation:< |
Implementation:<syntaxhighlight lang="J>divisors=: {{ \:~ */@>,{ (^ i.@>:)&.">/ __ q: y }} |
||
zum=: {{ |
zum=: {{ |
||
if. 2|s=. +/divs=. divisors y do. 0 |
if. 2|s=. +/divs=. divisors y do. 0 |
||
Line 2,319: | Line 2,319: | ||
else. s=. -:s for_d. divs do. if. d<:s do. s=. s-d end. end. s=0 |
else. s=. -:s for_d. divs do. if. d<:s do. s=. s-d end. end. s=0 |
||
end. |
end. |
||
}}@></ |
}}@></syntaxhighlight> |
||
Task examples:< |
Task examples:<syntaxhighlight lang="J"> 10 22$1+I.zum 1+i.1000 NB. first 220 Zumkeller numbers |
||
6 12 20 24 28 30 40 42 48 54 56 60 66 70 78 80 84 88 90 96 102 104 |
6 12 20 24 28 30 40 42 48 54 56 60 66 70 78 80 84 88 90 96 102 104 |
||
108 112 114 120 126 132 138 140 150 156 160 168 174 176 180 186 192 198 204 208 210 216 |
108 112 114 120 126 132 138 140 150 156 160 168 174 176 180 186 192 198 204 208 210 216 |
||
Line 2,341: | Line 2,341: | ||
351351 459459 513513 567567 621621 671517 729729 742203 783783 793611 |
351351 459459 513513 567567 621621 671517 729729 742203 783783 793611 |
||
812889 837837 891891 908523 960687 999999 1024947 1054053 1072071 1073709 |
812889 837837 891891 908523 960687 999999 1024947 1054053 1072071 1073709 |
||
1095633 1108107 1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377</ |
1095633 1108107 1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
< |
<syntaxhighlight lang="java"> |
||
import java.util.ArrayList; |
import java.util.ArrayList; |
||
import java.util.Collections; |
import java.util.Collections; |
||
Line 2,456: | Line 2,456: | ||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 2,497: | Line 2,497: | ||
generates a stream of partitions is easily transformed into a |
generates a stream of partitions is easily transformed into a |
||
specialized function that prunes irrelevant partitions efficiently. |
specialized function that prunes irrelevant partitions efficiently. |
||
< |
<syntaxhighlight lang="jq"># The factors, sorted |
||
def factors: |
def factors: |
||
. as $num |
. as $num |
||
Line 2,563: | Line 2,563: | ||
end |
end |
||
| true) |
| true) |
||
// false;</ |
// false;</syntaxhighlight><syntaxhighlight lang="jq">## The tasks: |
||
"First 220:", limit(220; range(2; infinite) | select(is_zumkeller)), |
"First 220:", limit(220; range(2; infinite) | select(is_zumkeller)), |
||
"" |
"" |
||
"First 40 odd:", limit(40; range(3; infinite; 2) | select(is_zumkeller))</ |
"First 40 odd:", limit(40; range(3; infinite; 2) | select(is_zumkeller))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,589: | Line 2,589: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia">using Primes |
||
function factorize(n) |
function factorize(n) |
||
Line 2,637: | Line 2,637: | ||
println("\n\nFirst 40 odd Zumkeller numbers not ending with 5:") |
println("\n\nFirst 40 odd Zumkeller numbers not ending with 5:") |
||
printconditionalnum((n) -> isodd(n) && (string(n)[end] != '5') && iszumkeller(n), 40, 8) |
printconditionalnum((n) -> isodd(n) && (string(n)[end] != '5') && iszumkeller(n), 40, 8) |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
First 220 Zumkeller numbers: |
First 220 Zumkeller numbers: |
||
Line 2,671: | Line 2,671: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{trans|Java}} |
{{trans|Java}} |
||
< |
<syntaxhighlight lang="scala">import java.util.ArrayList |
||
import kotlin.math.sqrt |
import kotlin.math.sqrt |
||
Line 2,779: | Line 2,779: | ||
return divisors |
return divisors |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>First 220 Zumkeller numbers: |
<pre>First 220 Zumkeller numbers: |
||
Line 2,807: | Line 2,807: | ||
=={{header|Lobster}}== |
=={{header|Lobster}}== |
||
< |
<syntaxhighlight lang="Lobster">import std |
||
// Derived from Julia and Python versions |
// Derived from Julia and Python versions |
||
Line 2,867: | Line 2,867: | ||
print "\n\n40 odd Zumkeller numbers:" |
print "\n\n40 odd Zumkeller numbers:" |
||
printZumkellers(40, true) |
printZumkellers(40, true) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,903: | Line 2,903: | ||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="Mathematica">ClearAll[ZumkellerQ] |
||
ZumkellerQ[n_] := Module[{d = Divisors[n], t, ds, x}, |
ZumkellerQ[n_] := Module[{d = Divisors[n], t, ds, x}, |
||
ds = Total[d]; |
ds = Total[d]; |
||
Line 2,929: | Line 2,929: | ||
i += 2; |
i += 2; |
||
]; |
]; |
||
res</ |
res</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>{6,12,20,24,28,30,40,42,48,54,56,60,66,70,78,80,84,88,90,96,102,104,108,112,114,120,126,132,138,140,150,156,160,168,174,176,180,186,192,198,204,208,210,216,220,222,224,228,234,240,246,252,258,260,264,270,272,276,280,282,294,300,304,306,308,312,318,320,330,336,340,342,348,350,352,354,360,364,366,368,372,378,380,384,390,396,402,408,414,416,420,426,432,438,440,444,448,456,460,462,464,468,474,476,480,486,490,492,496,498,500,504,510,516,520,522,528,532,534,540,544,546,550,552,558,560,564,570,572,580,582,588,594,600,606,608,612,616,618,620,624,630,636,640,642,644,650,654,660,666,672,678,680,684,690,696,700,702,704,708,714,720,726,728,732,736,740,744,750,756,760,762,768,770,780,786,792,798,804,810,812,816,820,822,828,832,834,836,840,852,858,860,864,868,870,876,880,888,894,896,906,910,912,918,920,924,928,930,936,940,942,945,948,952,960,966,972,978,980,984} |
<pre>{6,12,20,24,28,30,40,42,48,54,56,60,66,70,78,80,84,88,90,96,102,104,108,112,114,120,126,132,138,140,150,156,160,168,174,176,180,186,192,198,204,208,210,216,220,222,224,228,234,240,246,252,258,260,264,270,272,276,280,282,294,300,304,306,308,312,318,320,330,336,340,342,348,350,352,354,360,364,366,368,372,378,380,384,390,396,402,408,414,416,420,426,432,438,440,444,448,456,460,462,464,468,474,476,480,486,490,492,496,498,500,504,510,516,520,522,528,532,534,540,544,546,550,552,558,560,564,570,572,580,582,588,594,600,606,608,612,616,618,620,624,630,636,640,642,644,650,654,660,666,672,678,680,684,690,696,700,702,704,708,714,720,726,728,732,736,740,744,750,756,760,762,768,770,780,786,792,798,804,810,812,816,820,822,828,832,834,836,840,852,858,860,864,868,870,876,880,888,894,896,906,910,912,918,920,924,928,930,936,940,942,945,948,952,960,966,972,978,980,984} |
||
Line 2,936: | Line 2,936: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="Nim">import math, strutils |
||
template isEven(n: int): bool = (n and 1) == 0 |
template isEven(n: int): bool = (n and 1) == 0 |
||
Line 3,006: | Line 3,006: | ||
inc count |
inc count |
||
stdout.write if count mod 8 == 0: '\n' else: ' ' |
stdout.write if count mod 8 == 0: '\n' else: ' ' |
||
inc n, 2</ |
inc n, 2</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,038: | Line 3,038: | ||
Now using the trick, that one partition sum must include n and improved recursive search.<BR> |
Now using the trick, that one partition sum must include n and improved recursive search.<BR> |
||
Limit is ~1.2e11 |
Limit is ~1.2e11 |
||
< |
<syntaxhighlight lang="pascal">program zumkeller; |
||
//https://oeis.org/A083206/a083206.txt |
//https://oeis.org/A083206/a083206.txt |
||
{$IFDEF FPC} |
{$IFDEF FPC} |
||
Line 3,728: | Line 3,728: | ||
writeln('runtime ',(GetTickCount64-T0)/1000:8:3,' s'); |
writeln('runtime ',(GetTickCount64-T0)/1000:8:3,' s'); |
||
END. |
END. |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,809: | Line 3,809: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{libheader|ntheory}} |
{{libheader|ntheory}} |
||
< |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
use feature 'say'; |
use feature 'say'; |
||
Line 3,853: | Line 3,853: | ||
$n = 0; $z = ''; |
$n = 0; $z = ''; |
||
$z .= do { $n < 40 ? (!!($_%2 and $_%5) and is_Zumkeller($_) and ++$n and "$_ ") : last } for 1 .. Inf; |
$z .= do { $n < 40 ? (!!($_%2 and $_%5) and is_Zumkeller($_) and ++$n and "$_ ") : last } for 1 .. Inf; |
||
in_columns(10, $z);</ |
in_columns(10, $z);</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,883: | Line 3,883: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
<!--< |
<!--<syntaxhighlight lang="Phix>(phixonline)--"> |
||
<span style="color: #008080;">function</span> <span style="color: #000000;">isPartSum</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">f</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">)</span> |
<span style="color: #008080;">function</span> <span style="color: #000000;">isPartSum</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">f</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #008080;">if</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #004600;">true</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
<span style="color: #008080;">if</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #004600;">true</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
||
Line 3,927: | Line 3,927: | ||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span> |
||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,964: | Line 3,964: | ||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
< |
<syntaxhighlight lang="PicoLisp">(de propdiv (N) |
||
(make |
(make |
||
(for I N |
(for I N |
||
Line 4,015: | Line 4,015: | ||
(and |
(and |
||
(=0 (% C 8)) |
(=0 (% C 8)) |
||
(prinl) ) ) )</ |
(prinl) ) ) )</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 4,046: | Line 4,046: | ||
===Procedural=== |
===Procedural=== |
||
Modified from a footnote at OEIS A083207 (see reference in problem text) by Charles R Greathouse IV. |
Modified from a footnote at OEIS A083207 (see reference in problem text) by Charles R Greathouse IV. |
||
< |
<syntaxhighlight lang="python">from sympy import divisors |
||
from sympy.combinatorics.subsets import Subset |
from sympy.combinatorics.subsets import Subset |
||
Line 4,078: | Line 4,078: | ||
print("\n\n40 odd Zumkeller numbers:") |
print("\n\n40 odd Zumkeller numbers:") |
||
printZumkellers(40, True) |
printZumkellers(40, True) |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
220 Zumkeller numbers: |
220 Zumkeller numbers: |
||
Line 4,116: | Line 4,116: | ||
Relying on the standard Python libraries, as an alternative to importing SymPy: |
Relying on the standard Python libraries, as an alternative to importing SymPy: |
||
< |
<syntaxhighlight lang="python">'''Zumkeller numbers''' |
||
from itertools import ( |
from itertools import ( |
||
Line 4,318: | Line 4,318: | ||
# MAIN --- |
# MAIN --- |
||
if __name__ == '__main__': |
if __name__ == '__main__': |
||
main()</ |
main()</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>First 220 Zumkeller numbers: |
<pre>First 220 Zumkeller numbers: |
||
Line 4,355: | Line 4,355: | ||
{{trans|Zkl}} |
{{trans|Zkl}} |
||
< |
<syntaxhighlight lang="racket">#lang racket |
||
(require math/number-theory) |
(require math/number-theory) |
||
Line 4,395: | Line 4,395: | ||
(newline) |
(newline) |
||
(tabulate "First 40 odd Zumkeller numbers not ending in 5:" |
(tabulate "First 40 odd Zumkeller numbers not ending in 5:" |
||
(first-n-matching-naturals 40 (λ (n) (and (odd? n) (not (= 5 (modulo n 10))) (zum? n)))))</ |
(first-n-matching-naturals 40 (λ (n) (and (odd? n) (not (= 5 (modulo n 10))) (zum? n)))))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 4,419: | Line 4,419: | ||
(formerly Perl 6) |
(formerly Perl 6) |
||
{{libheader|ntheory}} |
{{libheader|ntheory}} |
||
< |
<syntaxhighlight lang="perl6>use ntheory:from<Perl5> <factor is_prime">; |
||
sub zumkeller ($range) { |
sub zumkeller ($range) { |
||
Line 4,449: | Line 4,449: | ||
# Stretch. Slow to calculate. (minutes) |
# Stretch. Slow to calculate. (minutes) |
||
put "\nFirst 40 odd Zumkeller numbers not divisible by 5:\n" ~ |
put "\nFirst 40 odd Zumkeller numbers not divisible by 5:\n" ~ |
||
zumkeller(flat (^Inf).map: {my \p = 10 * $_; p+1, p+3, p+7, p+9} )[^40].rotor(10)».fmt('%7d').join: "\n";</ |
zumkeller(flat (^Inf).map: {my \p = 10 * $_; p+1, p+3, p+7, p+9} )[^40].rotor(10)».fmt('%7d').join: "\n";</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>First 220 Zumkeller numbers: |
<pre>First 220 Zumkeller numbers: |
||
Line 4,478: | Line 4,478: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
The construction of the partitions were created in the order in which the most likely partitions would match. |
The construction of the partitions were created in the order in which the most likely partitions would match. |
||
< |
<syntaxhighlight lang="rexx">/*REXX pgm finds & shows Zumkeller numbers: 1st N; 1st odd M; 1st odd V not ending in 5.*/ |
||
parse arg n m v . /*obtain optional arguments from the CL*/ |
parse arg n m v . /*obtain optional arguments from the CL*/ |
||
if n=='' | n=="," then n= 220 /*Not specified? Then use the default.*/ |
if n=='' | n=="," then n= 220 /*Not specified? Then use the default.*/ |
||
Line 4,568: | Line 4,568: | ||
if p1==p2 then return 1 /*Partition sums equal? Then X is Zum.*/ |
if p1==p2 then return 1 /*Partition sums equal? Then X is Zum.*/ |
||
end /*part*/ |
end /*part*/ |
||
return 0 /*no partition sum passed. X isn't Zum*/</ |
return 0 /*no partition sum passed. X isn't Zum*/</syntaxhighlight> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
Line 4,591: | Line 4,591: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
load "stdlib.ring" |
load "stdlib.ring" |
||
Line 4,756: | Line 4,756: | ||
last -= 1 |
last -= 1 |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 4,782: | Line 4,782: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<syntaxhighlight lang="ruby">class Integer |
||
def divisors |
def divisors |
||
Line 4,818: | Line 4,818: | ||
puts "\n#{n=40} odd Zumkeller numbers not ending with 5:" |
puts "\n#{n=40} odd Zumkeller numbers not ending with 5:" |
||
p_enum 1.step(by: 2).lazy.select{|x| x % 5 > 0 && x.zumkeller?}.take(n) |
p_enum 1.step(by: 2).lazy.select{|x| x % 5 > 0 && x.zumkeller?}.take(n) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>220 Zumkeller numbers: |
<pre>220 Zumkeller numbers: |
||
Line 4,852: | Line 4,852: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
< |
<syntaxhighlight lang="rust"> |
||
use std::convert::TryInto; |
use std::convert::TryInto; |
||
Line 4,937: | Line 4,937: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 4,955: | Line 4,955: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<syntaxhighlight lang="ruby">func is_Zumkeller(n) { |
||
return false if n.is_prime |
return false if n.is_prime |
||
Line 4,988: | Line 4,988: | ||
say "\nFirst 40 odd Zumkeller numbers not divisible by 5: " |
say "\nFirst 40 odd Zumkeller numbers not divisible by 5: " |
||
say (1..Inf `by` 2 -> lazy.grep { _ % 5 != 0 }.grep(is_Zumkeller).first(40).join(' '))</ |
say (1..Inf `by` 2 -> lazy.grep { _ % 5 != 0 }.grep(is_Zumkeller).first(40).join(' '))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 5,002: | Line 5,002: | ||
=={{header|Standard ML}}== |
=={{header|Standard ML}}== |
||
< |
<syntaxhighlight lang="Standard ML"> |
||
exception Found of string ; |
exception Found of string ; |
||
Line 5,055: | Line 5,055: | ||
end; |
end; |
||
</syntaxhighlight> |
|||
</lang> |
|||
call loop and output - interpreter |
call loop and output - interpreter |
||
< |
<syntaxhighlight lang="Standard ML"> |
||
- val Zumkellerlist = fn step => fn no5 => |
- val Zumkellerlist = fn step => fn no5 => |
||
let |
let |
||
Line 5,090: | Line 5,090: | ||
742203, 783783, 793611, 812889, 837837, 891891, 908523, 960687, 999999, 1024947, 1054053, 1072071, 1073709, 1095633, 1108107, 1145529, |
742203, 783783, 793611, 812889, 837837, 891891, 908523, 960687, 999999, 1024947, 1054053, 1072071, 1073709, 1095633, 1108107, 1145529, |
||
1162161, 1198197, 1224531, 1270269, 1307691, 1324323, 1378377 |
1162161, 1198197, 1224531, 1270269, 1307691, 1324323, 1378377 |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Swift}}== |
=={{header|Swift}}== |
||
Line 5,096: | Line 5,096: | ||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="swift">import Foundation |
||
extension BinaryInteger { |
extension BinaryInteger { |
||
Line 5,156: | Line 5,156: | ||
print("First 220 zumkeller numbers are \(Array(zums.prefix(220)))") |
print("First 220 zumkeller numbers are \(Array(zums.prefix(220)))") |
||
print("First 40 odd zumkeller numbers are \(Array(oddZums.prefix(40)))") |
print("First 40 odd zumkeller numbers are \(Array(oddZums.prefix(40)))") |
||
print("First 40 odd zumkeller numbers that don't end in a 5 are: \(Array(oddZumsWithout5.prefix(40)))")</ |
print("First 40 odd zumkeller numbers that don't end in a 5 are: \(Array(oddZumsWithout5.prefix(40)))")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 5,166: | Line 5,166: | ||
=={{header|Visual Basic .NET}}== |
=={{header|Visual Basic .NET}}== |
||
{{trans|C#}} |
{{trans|C#}} |
||
< |
<syntaxhighlight lang="vbnet">Module Module1 |
||
Function GetDivisors(n As Integer) As List(Of Integer) |
Function GetDivisors(n As Integer) As List(Of Integer) |
||
Dim divs As New List(Of Integer) From { |
Dim divs As New List(Of Integer) From { |
||
Line 5,265: | Line 5,265: | ||
End While |
End While |
||
End Sub |
End Sub |
||
End Module</ |
End Module</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>The first 220 Zumkeller numbers are: |
<pre>The first 220 Zumkeller numbers are: |
||
Line 5,295: | Line 5,295: | ||
=={{header|Vlang}}== |
=={{header|Vlang}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="vlang">fn get_divisors(n int) []int { |
||
mut divs := [1, n] |
mut divs := [1, n] |
||
for i := 2; i*i <= n; i++ { |
for i := 2; i*i <= n; i++ { |
||
Line 5,382: | Line 5,382: | ||
} |
} |
||
println('') |
println('') |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 5,418: | Line 5,418: | ||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
I've reversed the order of the recursive calls in the last line of the ''isPartSum'' function which, as noted in the Phix entry, seems to make little difference to Go but (as one might have expected) speeds up this Wren script enormously. The first part is now near instant but was taking several minutes previously. Overall it's now only about 5.5 times slower than Go itself which is a good result for the Wren interpreter. |
I've reversed the order of the recursive calls in the last line of the ''isPartSum'' function which, as noted in the Phix entry, seems to make little difference to Go but (as one might have expected) speeds up this Wren script enormously. The first part is now near instant but was taking several minutes previously. Overall it's now only about 5.5 times slower than Go itself which is a good result for the Wren interpreter. |
||
< |
<syntaxhighlight lang="ecmascript">import "/math" for Int, Nums |
||
import "/fmt" for Fmt |
import "/fmt" for Fmt |
||
import "io" for Stdout |
import "io" for Stdout |
||
Line 5,484: | Line 5,484: | ||
i = i + 2 |
i = i + 2 |
||
} |
} |
||
System.print()</ |
System.print()</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 5,517: | Line 5,517: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
{{trans|Julia}} {{trans|Go}} |
{{trans|Julia}} {{trans|Go}} |
||
< |
<syntaxhighlight lang="zkl">fcn properDivs(n){ // does not include n |
||
// if(n==1) return(T); // we con't care about this case |
// if(n==1) return(T); // we con't care about this case |
||
( pd:=[1..(n).toFloat().sqrt()].filter('wrap(x){ n%x==0 }) ) |
( pd:=[1..(n).toFloat().sqrt()].filter('wrap(x){ n%x==0 }) ) |
||
Line 5,540: | Line 5,540: | ||
} |
} |
||
canSum(sum/2,ds) and n or Void.Skip // sum is even |
canSum(sum/2,ds) and n or Void.Skip // sum is even |
||
}</ |
}</syntaxhighlight> |
||
< |
<syntaxhighlight lang="zkl">println("First 220 Zumkeller numbers:"); |
||
zw:=[2..].tweak(isZumkellerW); |
zw:=[2..].tweak(isZumkellerW); |
||
do(11){ zw.walk(20).pump(String,"%4d ".fmt).println() } |
do(11){ zw.walk(20).pump(String,"%4d ".fmt).println() } |
||
Line 5,551: | Line 5,551: | ||
println("\nThe first 40 odd Zumkeller numbers which don't end in 5 are:"); |
println("\nThe first 40 odd Zumkeller numbers which don't end in 5 are:"); |
||
zw:=[3..*, 2].tweak(fcn(n){ if(n%5) isZumkellerW(n) else Void.Skip }); |
zw:=[3..*, 2].tweak(fcn(n){ if(n%5) isZumkellerW(n) else Void.Skip }); |
||
do(5){ zw.walk(8).pump(String,"%7d ".fmt).println() }</ |
do(5){ zw.walk(8).pump(String,"%7d ".fmt).println() }</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style="font-size:83%"> |
<pre style="font-size:83%"> |