## FANDOM

10,821 Pages

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 — 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)

# Test the algorithm with the usual factorial
# 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, 36):
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.

The script is unavoidably pretty slow. At about 20 digits, the runtime hits the 60-second mark.

## Algorithm

My Python is readable enough for the algorithm to make some sense, but here's the idea:

• Find all combinations of $$d$$ digits, counting repetitions (such as (0, 0, 1, 2, 4, 6, 6, 7, 7, 7, 9)).
• Sum the hyperfactorials of the digits using a precomputed table.
• Make sure the sum $$s$$ is between $$10^{d - 1}$$ and $$10^d$$.
• Check the actual digits by repeatedly dividing $$s$$ by 10 and removing the remainder from the combination. This is the blump function. (When I can't think of a good name for a function, I often call it blump. I offer no redeeming explanation.)