Teaser 2415: [Double shift]
From The Sunday Times, 4th January 2009 [link]
I have written down a large number in which no digit occurs more than twice. If I were to move the last digit of the number from the end to the front of the number, then the effect would be to double the number. If I repeated the process with the new number, then the effect would be to double it again. And if I repeated the process again, the effect would be to double the number yet again.
What is the number that I have written down?
This puzzle was originally published with no title.
[teaser2415]
Jim Randell 10:06 am on 27 January 2026 Permalink |
If we suppose the original number n is of the form:
Then moving the final digit to the front gives us:
From which we derive that a is a k-digit number, such that:
If the number contains no digit more than twice, then the longest the number can be is 20 digits long, and so we can consider k up to 19.
This Python program runs in 70ms. (Internal runtime is 719µs).
from enigma import (irange, div, nsplit, rotate, zip_eq, seq2str, printf) # check a candidate number <n> (with digits <ds>) def check(n, ds): # check no digit occurs more than twice if any(ds.count(x) > 2 for x in set(ds)): return # record shifts that result in doublings ns = [n] # collect doubling sequences while True: n *= 2 ds = rotate(ds, -1) if not zip_eq(ds, nsplit(n)): break ns.append(n) return ns # look for up to 19 digits prefixes for k in irange(1, 19): x = 10**k - 2 # consider possible final digits for z in irange(1, 9): a = div(x * z, 19) if a is None: continue n = 10*a + z ds = nsplit(n) if len(ds) != k + 1: continue ns = check(n, ds) if ns and len(ns) >= 4: printf("{ns}", ns=seq2str(ns, sep=" -> ", enc=""))Solution: The number is: 105263157894736842.
The number is 18 digits long, and uses each digit twice except 0 and 9 (which are used once each).
Shifting the final digit to the front multiple times we get:
A run of 4 is the longest run we can get in base 10 (as n × 16 will not have the same number of digits as n), but there is another run of 3 we can make:
These numbers are the repetends of fractions of the form k / 19.
LikeLike
Frits 8:51 am on 31 January 2026 Permalink |
''' n = xbcd where x is a k-digit number and b,c and d are digits 2.n = dxbc 4.n = cdxb 8.n = bcdx with x, b and c all even 8.n = bcdx also has k+3 digits so b = 8 and first digit of x = 1 --> c = 4 (not 9) and last digit of x must be 6 d = 2 (as 2.n must be 2.....) n = 1....6842 n = xbcd = 1000.x + bcd (x has k digits) 8.n = bcdx = 10^k . bcd + x 8000.x + 8.bcd = 10^k . bcd + x 7999.x = 19.421.x = (10^k - 8).842 19.x = 2.(10^k - 8) ''' for k in range(2, 18): x, r = divmod(2 * (10**k - 8), 19) if r: continue n = str(x) + "842" # no digit occurs more than twice if all(n.count(str(i)) <= 2 for i in range(10)): print("answer method 1:", n) # in order for 2 * (10**k - 8) % 19 = 0 we must have # 2 * 10**k % 19 = 16 # 2 * 10**k = 19.10**(k - 1) + 10**(k - 1) # so 10**(k - 1) % 19 = 16 # 10**(k - 1) % 19 follows a logical pattern k = 2 a = 10**(k - 1) % 19 while a != 16: a = (a + 19 * (a % 2)) // 2 k += 1 n = str(2 * (10**k - 8) // 19) + "842" # no digit occurs more than twice if all(n.count(str(i)) <= 2 for i in range(10)): print("answer method 2:", n)LikeLike