How to resolve the algorithm Zumkeller numbers step by step in the Mathematica / Wolfram Language programming language
How to resolve the algorithm Zumkeller numbers step by step in the Mathematica / Wolfram Language programming language
Table of Contents
Problem Statement
Zumkeller numbers are the set of numbers whose divisors can be partitioned into two disjoint sets that sum to the same value. Each sum must contain divisor values that are not in the other sum, and all of the divisors must be in one or the other. There are no restrictions on how the divisors are partitioned, only that the two partition sums are equal.
Even Zumkeller numbers are common; odd Zumkeller numbers are much less so. For values below 10^6, there is at least one Zumkeller number in every 12 consecutive integers, and the vast majority of them are even. The odd Zumkeller numbers are very similar to the list from the task Abundant odd numbers; they are nearly the same except for the further restriction that the abundance (A(n) = sigma(n) - 2n), must be even: A(n) mod 2 == 0
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Zumkeller numbers step by step in the Mathematica / Wolfram Language programming language
The provided Wolfram code is used to generate Zumkeller numbers. Zumkeller numbers are a sequence of positive integers for which the sum of the divisors of the number is an odd number and the central coefficient of the divisor polynomial is positive.
The code begins by defining a function called ZumkellerQ
that takes a positive integer n
as input and returns True
if n
is a Zumkeller number and False
otherwise.
Inside the ZumkellerQ
function:
- It calculates the divisors of
n
and stores them in the listd
. - It calculates the sum of the divisors and stores it in the variable
ds
. - It checks if
ds
is odd. If it is odd, the function returnsFalse
because a Zumkeller number must have an odd sum of divisors. - If
ds
is even, it constructs a polynomial using the divisors ind
and stores the coefficients of the polynomial in the listt
. - It checks if the central coefficient of the polynomial
t[[1 + ds/2]]
is positive. If it is positive, the function returnsTrue
, indicating thatn
is a Zumkeller number.
After defining the ZumkellerQ
function, the code generates two lists of Zumkeller numbers:
- The first list,
res
, contains the first 220 Zumkeller numbers. It does this by iterating through positive integers, checking if each integer is a Zumkeller number using theZumkellerQ
function, and adding it to the list if it is. - The second list,
res
, contains the first 40 odd Zumkeller numbers. It does this by iterating through odd positive integers, checking if each integer is a Zumkeller number, and adding it to the list if it is.
Finally, the code prints the two lists of Zumkeller numbers.
Source code in the wolfram programming language
ClearAll[ZumkellerQ]
ZumkellerQ[n_] := Module[{d = Divisors[n], t, ds, x},
ds = Total[d];
If[Mod[ds, 2] == 1,
False
,
t = CoefficientList[Product[1 + x^i, {i, d}], x];
t[[1 + ds/2]] > 0
]
];
i = 1;
res = {};
While[Length[res] < 220,
r = ZumkellerQ[i];
If[r, AppendTo[res, i]];
i++;
];
res
i = 1;
res = {};
While[Length[res] < 40,
r = ZumkellerQ[i];
If[r, AppendTo[res, i]];
i += 2;
];
res
You may also check:How to resolve the algorithm Mutual recursion step by step in the J programming language
You may also check:How to resolve the algorithm Associative array/Iteration step by step in the Rust programming language
You may also check:How to resolve the algorithm Elementary cellular automaton/Random number generator step by step in the Java programming language
You may also check:How to resolve the algorithm Short-circuit evaluation step by step in the jq programming language
You may also check:How to resolve the algorithm Terminal control/Ringing the terminal bell step by step in the C programming language