0
$\begingroup$

Here are two instances of an Kaprekar number

$\text{9${}^{\wedge} $2 = 81 $\&$ 8+1=9}$

$\text{8${}^{\wedge} $3 = 512 $\&$ 5+1+2=8}$

There are certainly more with a higher exponent , perhaps an infinite number of them.

However with the line of code below

FindInstance[ x^y == z  && x > 1 && y > 1  && Total[IntegerDigits[z]] == x, {x, y, z}, Integers, 1]

MMA V11.3 does not return a single instance. Is there anything wrong in this code or is it a limitation of the FindInstance function ?

$\endgroup$
  • $\begingroup$ Just curious: you write the formulas in LaTeX, which is a way to typeset traditional mathematical notation on a computer, but you make special effort to make it look like computer code regardless. Why? $\endgroup$ – Szabolcs Feb 22 at 12:57
  • $\begingroup$ 12.0 gives you a reason: "The methods available to FindInstance are insufficient to find the requested instances or prove they do not exist." If you reformulate the problem to avoid Total and IntegerDigits, then it works, but then we need to hard-code the number of digits. $\endgroup$ – Szabolcs Feb 22 at 13:11
  • $\begingroup$ Your definition of a Kaprekar number does not agree with the definition given in MathWorld or OEIS A006886. For those definitions, 8 is not a Kaprekar number. The OEIS gives the Mathematica code written by T. D. Noe which generates 1035 Kaprekar numbers. $\endgroup$ – Bob Hanlon Feb 22 at 14:01
  • $\begingroup$ According to mrob 8 is an order-3 Kaprekar number and 9 an order-2 (normal) one. The contents of your links don't contradict the one I point to but they are not as exhaustive. True I overlooked in my code to divide z into y equal pieces before adding them up.But I know now from the answer received that FindInstance is not up to the task even with V12.0 (version I don't have) which at first not evident. $\endgroup$ – Sigis K Feb 22 at 18:48
2
$\begingroup$

Brute-force search will be much better here than FindInstance.

In[16]:= First@Last@Reap@Do[
    If[Total@IntegerDigits[x^y] == x, Sow[{x, y}]],
    {x, 2, 20}, {y, 2, 10}
    ]

Out[16]= {{7, 4}, {8, 3}, {9, 2}, {17, 3}, {18, 3}, {18, 6}, {18, 7}}
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.