Zumkeller numbers: Difference between revisions

m
Reverted edits by MikeMol (talk) to last revision by [[User:rosettacode>Rdm|rosettacode>Rdm]]
(lang tag update)
Tag: Reverted
m (Reverted edits by MikeMol (talk) to last revision by [[User:rosettacode>Rdm|rosettacode>Rdm]])
Tag: Rollback
Line 37:
{{trans|D}}
 
<syntaxhighlight lang=" 11l">F getDivisors(n)
V divs = [1, n]
V i = 2
Line 145:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang=" AArch64 Assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program zumkellex641.s */
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.
 
<syntaxhighlight lang=" applescript">-- Sum n's proper divisors.
on aliquotSum(n)
if (n < 2) then return 0
Line 822:
 
{{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
102 104 108 112 114 120 126 132 138 140 150 156 160 168 174 176 180 186 192 198
Line 849:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang=" ARM Assembly">
/* ARM assembly Raspberry PI */
/* program zumkeller4.s */
Line 1,560:
=={{header|C sharp|C#}}==
{{trans|Go}}
<syntaxhighlight lang=" csharp">using System;
using System.Collections.Generic;
using System.Linq;
Line 1,684:
 
=={{header|C++}}==
<syntaxhighlight lang=" cpp>#include <iostream">
#include <cmath>
#include <vector>
Line 1,871:
=={{header|D}}==
{{trans|C#}}
<syntaxhighlight lang=" d">import std.algorithm;
import std.stdio;
 
Line 1,991:
=={{header|F_Sharp|F#}}==
This task uses [https://rosettacode.org/wiki/Sum_of_divisors#F.23]
<syntaxhighlight lang=" fsharp">
// 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
Line 2,013:
=={{header|Factor}}==
{{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 ;
 
Line 2,085:
 
=={{header|Go}}==
<syntaxhighlight lang=" go">package main
 
import "fmt"
Line 2,208:
=={{header|Haskell}}==
{{Trans|Python}}
<syntaxhighlight lang=" haskell">import Data.List (group, sort)
import Data.List.Split (chunksOf)
import Data.Numbers.Primes (primeFactors)
Line 2,313:
 
=={{header|J}}==
Implementation:<syntaxhighlightlang lang="J>divisors=: {{ \:~ */@>,{ (^ i.@>:)&.">/ __ q: y }}
zum=: {{
if. 2|s=. +/divs=. divisors y do. 0
Line 2,321:
}}@></lang>
 
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
108 112 114 120 126 132 138 140 150 156 160 168 174 176 180 186 192 198 204 208 210 216
Line 2,343:
1095633 1108107 1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377</lang>
=={{header|Java}}==
<syntaxhighlight lang=" java">
import java.util.ArrayList;
import java.util.Collections;
Line 2,497:
generates a stream of partitions is easily transformed into a
specialized function that prunes irrelevant partitions efficiently.
<syntaxhighlight lang=" jq"># The factors, sorted
def factors:
. as $num
Line 2,563:
end
| true)
// false;</lang><syntaxhighlight lang=" jq">## The tasks:
 
"First 220:", limit(220; range(2; infinite) | select(is_zumkeller)),
Line 2,589:
 
=={{header|Julia}}==
<syntaxhighlight lang=" julia">using Primes
 
function factorize(n)
Line 2,671:
=={{header|Kotlin}}==
{{trans|Java}}
<syntaxhighlight lang=" scala">import java.util.ArrayList
import kotlin.math.sqrt
 
Line 2,807:
 
=={{header|Lobster}}==
<syntaxhighlight lang=" Lobster">import std
 
// Derived from Julia and Python versions
Line 2,903:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight lang=" Mathematica">ClearAll[ZumkellerQ]
ZumkellerQ[n_] := Module[{d = Divisors[n], t, ds, x},
ds = Total[d];
Line 2,936:
=={{header|Nim}}==
{{trans|Go}}
<syntaxhighlight lang=" Nim">import math, strutils
 
template isEven(n: int): bool = (n and 1) == 0
Line 3,038:
Now using the trick, that one partition sum must include n and improved recursive search.<BR>
Limit is ~1.2e11
<syntaxhighlight lang=" pascal">program zumkeller;
//https://oeis.org/A083206/a083206.txt
{$IFDEF FPC}
Line 3,809:
=={{header|Perl}}==
{{libheader|ntheory}}
<syntaxhighlight lang=" perl">use strict;
use warnings;
use feature 'say';
Line 3,883:
=={{header|Phix}}==
{{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;">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,964:
 
=={{header|PicoLisp}}==
<syntaxhighlight lang=" PicoLisp">(de propdiv (N)
(make
(for I N
Line 4,046:
===Procedural===
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
Line 4,116:
Relying on the standard Python libraries, as an alternative to importing SymPy:
 
<syntaxhighlight lang=" python">'''Zumkeller numbers'''
 
from itertools import (
Line 4,355:
{{trans|Zkl}}
 
<syntaxhighlight lang=" racket">#lang racket
 
(require math/number-theory)
Line 4,419:
(formerly Perl 6)
{{libheader|ntheory}}
<syntaxhighlight lang=" perl6>use ntheory:from<Perl5> <factor is_prime">;
 
sub zumkeller ($range) {
Line 4,478:
=={{header|REXX}}==
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*/
if n=='' | n=="," then n= 220 /*Not specified? Then use the default.*/
Line 4,591:
 
=={{header|Ring}}==
<syntaxhighlight lang=" ring">
load "stdlib.ring"
 
Line 4,782:
 
=={{header|Ruby}}==
<syntaxhighlight lang=" ruby">class Integer
def divisors
Line 4,852:
 
=={{header|Rust}}==
<syntaxhighlight lang=" rust">
use std::convert::TryInto;
 
Line 4,955:
 
=={{header|Sidef}}==
<syntaxhighlight lang=" ruby">func is_Zumkeller(n) {
 
return false if n.is_prime
Line 5,002:
 
=={{header|Standard ML}}==
<syntaxhighlight lang=" Standard ML">
exception Found of string ;
 
Line 5,057:
</lang>
call loop and output - interpreter
<syntaxhighlight lang=" Standard ML">
- val Zumkellerlist = fn step => fn no5 =>
let
Line 5,096:
{{trans|Go}}
 
<syntaxhighlight lang=" swift">import Foundation
 
extension BinaryInteger {
Line 5,166:
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<syntaxhighlight lang=" vbnet">Module Module1
Function GetDivisors(n As Integer) As List(Of Integer)
Dim divs As New List(Of Integer) From {
Line 5,295:
=={{header|Vlang}}==
{{trans|Go}}
<syntaxhighlight lang=" vlang">fn get_divisors(n int) []int {
mut divs := [1, n]
for i := 2; i*i <= n; i++ {
Line 5,418:
{{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.
<syntaxhighlight lang=" ecmascript">import "/math" for Int, Nums
import "/fmt" for Fmt
import "io" for Stdout
Line 5,517:
=={{header|zkl}}==
{{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
( pd:=[1..(n).toFloat().sqrt()].filter('wrap(x){ n%x==0 }) )
Line 5,541:
canSum(sum/2,ds) and n or Void.Skip // sum is even
}</lang>
<syntaxhighlight lang=" zkl">println("First 220 Zumkeller numbers:");
zw:=[2..].tweak(isZumkellerW);
do(11){ zw.walk(20).pump(String,"%4d ".fmt).println() }