## Muenchhausen Numbers

### December 6, 2019

We use a simple function to calculate the sum of the digits, each digit raised to the power of itself:

(define (f n) (define (power n) (vector-ref '#(0 1 4 27 256 3125 46656 823543 16777216 387420489) n)) (sum (map power (digits n))))

> (do ((n 0 (+ n 1))) (#f) (when (= (f n) n) (display n) (newline))) 0 1 3435 438579088

For strict Muenchausen numbers, change the 0 entry in the vector to 1. See A046253 for more details, including a reference to a proof that the cardinality of the set of Muenchhausen numbers for any radix is finite; a Muenchhausen number in base *b* cannot be greater than 2*b ^{b}*.

A166623 gives the sequences of strict Muenchausen numbers for radices 2 to 35, along with a clever program for calculating them.

You can run the program at https://ideone.com/WZmiRy.

Here is my take on this in Julia (v. 1.1.1): https://pastebin.com/eppLUrZb

The result is this (fairly short) array: 1, 3435, 438579088

Note that I used the strict definition of Muenchhausen numbers, as it makes for a more interesting collection of numbers. Also, I set a limit of 1 billion when searching through the integer space to save time. Besides, it’s quite unlikely that there are any Muenchhausen numbers larger than that.

Have a nice weekend!

Here’s a variation on that algorithm by Chai Wah Wu on http://oeis.org/A166623: generate all digit combinations of length up to radix+2 (this covers the range 2r^r), calculate the digit sum, then see if that sum has the same digits as the original combination – if so, we have a Münchhausen number. Use 0 or 1 for “zeroval” to set the assumed value for 0^0:

That python program runs happily up to radix 15, but I got bored waiting for hexadecimal, so converted it into C++, which finds 1, c76712ffc311e6e and c4ef722b782c26f, along with c4ef722b7820c2f and 123b2309ff572f6b if we put 0^0 = 0 (not the usual convention). Calculations are done with uint64_t which gives just enough bits to check up to 16^16, which is apparently an adequate bound. There is a possibility that the sum might wrap around and we get a false positive, but that doesn’t seem to happen here. Results agree with https://github.com/elizarov/MunchausenNumbers/ which has an interesting meet-in-the-middle algorithm.

Runtime is about 40 seconds with g++ -O3

Python just got finished radix 16, so here are the full results with 0^0 = 1, and numbers in their proper radixes:

0^0 = 1, not undefined.

The situation is complex: https://en.wikipedia.org/wiki/Zero_to_the_power_of_zero

Also, this video can help shed some light on the 0^0 topic: https://youtu.be/UKqoXMyp4_U

Whatever the case, it’s always useful to remember that the Mathematics we is largely based on conventions and assumptions we have made about certain matters (e.g. Euclid’s axiom about the parallel lines). So, regardless of what 0^0 is in reality (if there is a way to access that kind of truth), what we accept it to be may be a matter of debate. In my experience as an engineer / scientist, figuring out a solution to a problem using Math is much more useful than any philosophical discussions about Math properties. I hope that helps. Cheers!

Klong version 20190209

It figures out the first 3 (0, 1, 3435) as soon as I run the code. The last number (438579088) takes 2-3 hours.

Here’s a GMP-based C++ solution. Combinations are visited using a library I wrote, revdoor.

Example usage for some radixes up to 20 follows the code. The radix of the output numbers corresponds to the specified radix.

For the examples I ran, the runtime scaled approximately exponentially, base 4, for each increment in the radix. E.g., radix 16 took 1.5 minutes, radix 17 took 6 minutes, radix 18 took 23 minutes, radix 19 took 91 minutes, and radix 20 took 334 minutes.

Example usage:

Here’s a variant of my solution above, modified to conduct the search in parallel.

GMP and revdoor are the existing dependencies, with OpenMP added for multiprocessing functionality.

Each process explores a different subset of combinations. A combination unranking function is used to map combination indices to the corresponding combinations, which are used to determine where each process should start its search.

Example comparing 16 threads and 1 thread: