User blog:Vel!/Hyperfactorial digits

In base 10, there are two numbers that are equal to the sums of the factorials of their digits: \(145 = 1! + 4! + 5!\) and \(40585 = 4! + 0! + 5! + 8! + 5!\). Although this fact is useless, it's pretty cool.

Most people would be content by now, but since we're googologists, we need to take this a step further using the hyperfactorial \(H(n) = 1^1 \cdot 2^2 \cdot 3^3 \cdot \cdots \cdot n^n\). Here's the problem:


 * Is there a positive integer in base 10 equal to the sums of the hyperfactorials of its digits? If so, what is it?

Fortunately, we only have a finite number of answers to check &mdash; up to \(10^36\). That's still way too big to brute-force. Deedlit11 suggested building from the digits up, which is a reasonable optimization.

I wrote the following Python 3 program to search for the solution:

import math import time from itertools import combinations_with_replacement

hyper = [1] r = 1 for i in range(1, 10): r *= i ** i   hyper.append(r)


 * 1) Test the algorithm with the usual factorial
 * 2) hyper = [math.factorial(d) for d in range(10)]

def blump(s, li): """Check whether s has li as its digits in any order.""" while s > 0: s, d = divmod(s, 10) try: li.remove(d) except ValueError: return False return li == []

tt = time.clock

for i in range(2, 35): print("{} digits".format(i)) b1, b2 = 10 ** (i - 1), 10 ** i   t = time.clock for c in combinations_with_replacement(range(10), i): s = sum([hyper[d] for d in c]) if b1 <= s < b2 and blump(s, list(c)): print("\x1b[32m*** SOLUTION FOUND: {} ***\x1b[0m".format(s)) print("Runtime: {:.2f}s".format(time.clock - t))

print("Computation completed in {:.2f}s.".format(time.clock - tt))

The program found no solutions up to 30 digits, and then, despite the ice pack, my laptop overheated and died horribly in this California heat wave. Oh well.