I wanted to try my hand at it from a principled way, by creating an equation for it.
The simple case of single digits is obvious, so let's start our equations with 2 digits of interest: ie, we are looking for (a, b, n) such that a.b0... = (a + b) / n
.
a + b / 10 = (a + b) / n
<=> n . a + n . b / 10 = a + b
<=> (n - 1) . a = (1 - n / 10) . b
<=> a = b . (1 - n / 10) / (n - 1)
Now, we can attempt to solve the equation for various values of n
:
We restrict ourselves to a and b in [1, 2, 3, 4, 5, 6, 7, 8, 9], as a = 0 or b = 0 are trivial cases.
- For n = 2 we get a = b . 4 / 5
, and thus a = 4
and b = 5
, that is: 4.5 = 9 / 2
.
- For n = 3 we get a = b . 7 / 20
, and no value of b
will make up that 20.
- For n = 4 we get a = b / 5
, and thus a = 1
and b = 5
, that is: 1.500 = 6 / 4
.
- For n = 5 we get a = b / 8
, and thus a = 1
and b = 8
, that is: 1.8000 = 9 / 5
.
- For n = 6 we get a = b . 2 / 25
, and no value of b
will make up that 25.
- For n = 7 we get a = b / 20
, and no value of b
will make up that 20.
- For n = 8 we get a = b / 35
, and no value of b
will make up that 35.
Given the fact that the denominator will only grow from there, and that the quotient b / a
cannot exceed 9, there's no point in looking any further.
As a recap, we have gathered the following solutions:
4.5 = 9 / 2, 1.500 = 6 / 4, and 1.8000 = 9 / 5.
We can similarly proceed with (a, b, c, n) such at a.bc0... = (a + b + c) / n
.
a + b / 10 + c / 100 = (a + b + c) / n
<=> n . a + n . b / 10 + n . c / 100 = a + b + c
<=> (n - 1) . a = (1 - n / 10) . b + (1 - n / 100) . c
<=> a = (b . (1 - n / 10) + c . (1 - n / 100)) / (n - 1)
Which we can once again attempt to solve for various values of n
:
We restrict ourselves to:
- a and c being non-zero digits, otherwise we fall back to the previous study.
- while b can be any digit.
And from there:
- For n = 3 we get a = (b . 70 + c . 97) / 200
, and just looking at the digits of the numerator tells us there's no solution with c non-zero.
- For n = 4 we get a = (b . 15 + c . 24) / 75
, once again, looking at the digits of the numerator, we notice that there's no solution with c != 5. With c = 5, we find a = 2 and b = 2, that is: 2.250 = 9 / 4
, as well as a = 3 and b = 7, that is 3.750 = 15 / 4
.
- For n = 5 we get a = (b . 10 + c . 19) / 80
, and just looking at the digits of the numerator tells us there's no solution with c non-zero.
- For n = 6 we get a = (b . 20 + c . 47) / 250
, nope.
- For n = 7 we get a = (b . 10 + c . 31) / 200
, nope.
- For n = 8 we get a = (b . 5 + c . 23) / 175
, no solution with c != 5, and the denominator is too large for b to make it up when c = 5.
- For n = 9 we get a = (b . 10 + c . 91) / 800
, nope.
- For n = 10 we get a = c / 10
, and the denominator has grown too large for c to make up.
As a recap, we have gathered the following solutions:
2.250 = 9 / 4, and 3.750 = 15 / 4.
Observation:
It seems that in a multi-digits solution, there cannot be a solution in which the smallest non-zero digit is not 5, as otherwise it doesn't add-up cleanly with the previous smallest digit.
Automating the search with Python does not yield any more results beyond:
- For 4 digits, we find for n = 8, a = 1, b = 1, c = 2, and d = 5, or 1.1250000 = 9 / 8
.
- For 5 digits, we find 1.6875 = 27 / 16
.
And I do wish I had a more principled explanation for this.
Program:
from fractions import Fraction
def solve_rec(n, n_digits):
def rec(n, den, fac, digits, acc):
if den == fac:
denominator = den * (n - 1)
if acc <= 0 or acc % denominator != 0:
return
a = acc // denominator
digits = [a] + digits
print("n = ", n, ", list = ", digits, ", fraction =", sum(digits), "/", n)
return
numerator = den - fac * n
for digit in range(0, 10):
new_acc = acc + digit * numerator
if new_acc % (fac * 10) != 0:
continue
rec(n, den, fac * 10, [digit] + digits, new_acc)
last_numerator = 10 ** n_digits - n
for last in range(1, 10):
accumulator = last * last_numerator
if accumulator % 10 != 0:
continue
rec(n, 10 ** n_digits, 10, [last], accumulator)
if name == 'main':
import sys
limit = int(sys.argv[1])
for n_digits in range(1, 10):
for n in range(n_digits + 1, limit + 1):
solve_rec(n, n_digits)