Digit Cancelling Fractions¶
The search term for this concept is an anomalous cancellation. We can write a function that checks if an anomalous cancellation can happen by storing the digits of the numerator and denominator into four variables total, then checking four separate cases for if a digit can be "cancelled."
In [1]:
def digits(n):
return (n // 10, n % 10)
def can_cancel_digits(n, d):
x, y = digits(n)
z, w = digits(d)
f = QQ(n/d)
if x == z and w != 0 and y/w == f:
return True
elif x == w and y/z == f:
return True
elif y == z and w != 0 and x/w == f:
return True
elif y == w and w != 0 and x/z == f:
return True
return False
We're only dealing with two-digit numerators and denominators, so this is easy to brute force.
In [2]:
fractions = set()
for n in range(10, 100):
for d in range(n + 1, 100):
if can_cancel_digits(n, d):
fractions.add((n, d))
fractions
Out[2]:
{(16, 64), (19, 95), (26, 65), (49, 98)}
There's only four such fractions.
In [3]:
prod(QQ(n/d) for (n, d) in fractions).denominator()
Out[3]:
100
Copyright (C) 2025 filifa¶
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license and the BSD Zero Clause license.