I’m sad to report (though you may already know this), that the Riddler, the awesome puzzle/riddle-solving feature of FiveThirtyEight is defunct. Thankfully, Zach Wissner-Gross—former editor—runs Fiddler on the Proof, a spiritual successor.
This week’s problem invovles taking an integer, adding up its digits, and adding up that number’s digits.
Here’s the text of the problem:
From Tom Rich comes a short-ish puzzle with a long-ish answer:
For any positive, base-10 integer $N$, define $f(N)$ as the number of times you have to add up its digits until you get a one-digit number. For example, $f(23)$ = 1 because 2+3 = 5, a one-digit number. Meanwhile, $f(888)$ = 2, since 8+8+8 = 24, a two-digit number, and then adding up those digits gives you 2+4 = 6, a one-digit number.
Find the smallest whole number $N$ such that $f(N)$ = 4.
The bonus problem is:
Now that you’ve had some fun with larger numbers, let’s return to more mundane orders of magnitude.
For how many whole numbers $N$ between 1 and 10,000 (inclusive, not that it matters) does $f(N)$ = 3?
To come up with a solution, I actually started with the bonus problem to help myself find some patterns. We’ll flex our Python muscles a little bit and write a function which takes in a number and conducts the operation described in the column.
import numpy as np
def digits(n):
current_n = n
f = 1
sum_split = sum([int(d) for d in str(current_n)])
if sum_split < 10:
result = [(n, f, sum_split)]
else:
result = []
while sum_split >= 10:
split_n = [int(d) for d in str(current_n)]
sum_split = sum(split_n)
current_n = sum_split
result.append((n, f, sum_split))
f += 1
return result
Starting from an initial $f$ of 1 and the starting number $n$, we take the sum of its digits. If the sum of its digits is less than 10, then we return the original number, $f = 1$, and the sum of its digits. Otherwise, we loop until the sum of its digits is less than 10, taking into account each step along the way.
Repeating this function from 1 through 10,000 yields our answer of 945.
ints = np.arange(1, 10000)
results = [digits(n) for n in ints]
max_f_values = []
for result in results:
f_values = [item[1] for item in result]
max_f = max(f_values) if f_values else 0
max_f_values.append(max_f)
f_3 = [ints[i] for i, f in enumerate(max_f_values) if f == 3]
len(f_3)
Integers from 1 through 10,000 only contain results that are of $f = 1$, $f = 2$, or $f = 3$. Focusing in on the lowest number that returns a change in $f$ reveals a clear pattern that allowed me to find a solution for the first problem.
Obviously for $f = 1$ only one step is needed, but for $f = 2$, 19 is the lowest number that yields this result. $1 + 9$ is 10, and $1 + 0$ is 1. Similarly, for $f = 3$, 199 is the lowest number that yields that result $1 + 9 + 9$ is $19$ and then the procedure follows in the same manner. Therefore, to find the next number in the sequence, we need to find the number whose sum of digits is $199$.
9 is clearly the digit that we want to use the most in this number, since we want to minimize the size of the number. If we divide 199 by 9, we actually find our answer: we need 22 9’s, but there is a remainder of $\frac{1}{9}$. To account for the remainder the lowest number we can possibly choose is is 1. Where should we put it? At the front of the number, since if we put it at the end, we end up having to add another nine and therefore increase the size of the number.
Therefore, the answer is:
\[19,999,999,999,999,999,999,999\]or 19 sextillion, 999 quintillion, 999 quadrillion, 999 trillion, 999 billion, 999 million, 999 thousand, 999.
To go up a step such that $f = 5$, we would need to find a number whose digits sum to 19,999,999,999,999,999,999,999, and that would be a very large number indeed!
comments powered by Disqus