While attending W.G.’s birthday party I reminded him that exactly one year ago I presented (double entendre) him a 15 digit number and challenged him to examine its structure and using any method to keep it in memory for another year.
“Yes, I sure remember it’s structure”, quipped he. “ Your number was composed of three 5-digit parts, each containing the same 5 distinct digits, the 1st had 4 successive digits like 1234 and additional digit, the second was like the 1st reversed and the 3rd used the same digits in a higgledy-piggledy arrangement. There were no leading zeroes, but to reconstruct the whole number I need some additional input….Otherwise there are like (paused for a minute) 1180 possible valid solutions…”
“OK, I do not check this number, and I am more than happy to inform you that adding the 3 components of the 15-digit chain I got 175497.”
a. Could WG decipher my number?
b. How about you?
c. Is the 1180 correct number?
I assume the 4 in a row digits are only increasing. I think that is something WG would have a clear memory
Answers:
a. Not without knowing the sum.
b. Yes. 345688654354386
Although if 4 decreasing digits are an option, then a different solution is 865433456854386
(which is simply exchanging the second 5 digits with the first 5 digits)
c. No. The exact number depends on what WG is assuming is known. [Edit: 5900 ways]
[Edited after communicating with Ady. Assumptions clarified. Indeed the answer to 'c' is dependent on the assumptions regarding what WG noticed and remembered.
Assumptions:
1. The 4 in a row digits cannot include 0123 due to no leading zeros. Although a prefixed additional number, e.g., 80123 would not have a leading zero, nevertheless the 0123 option is disallowed.
2. The additional digit cannot convert the 4 in a row digits to 5 in a row; we are to assume WG would have noticed that.
3. The higgledy-piggledy arrangement of the third set of 5 digits cannot be identical to either the first or second group of 5. WG would have noticed that, we are to assume.
There are 6 ways to have 4 in a row digits. These are all nonzero, and the additional digit must be nonzero. In general there are 5 other choices (all nonzero) for the additional digit, but limited by the condition of not converting it into 5 in a row. In fact, if 1234 is prefixed, or 6789 is postfixed, it can be with any of 5 digits. But in all other cases, the prefixing and postfixing can only be with 4 digits, since 5 in a row is disallowed.
The first group can be any of 6*4*2 + 2 ways. Or 50 ways.
Given a first group, the second group is the reverse: only one way.
The third group of 5 digits can occur in 5! ways, except we must subtract 2 since it cannot be identical to the either of the other groups. That's 118 ways.
Final answer: 50*118 = 5900 ]
Program notes:
Function addrev takes the first 5 digits and adds that to the reverse of the first 5 digits.
The third 5 digits are then a simple subtraction of that sum from 175497; check to see if it is composed of the same 5 digits.
-----------
def addrev(n):
n = int(n)
s = str(n)
r = int(s[::-1])
return n+r
firsts = []
digits = '0123456789'
# digits = '9876543210'
runsof4 = []
for i in range(1,7):
runsof4.append(digits[i:i+4])
for r in runsof4:
others = digits
for char in r:
others = others.replace(char, '')
for o in others:
if o != '0':
firsts.append(o + r)
firsts.append(r + o)
for f in firsts:
third = str(175497 - addrev(f))
if len(third) > 5 or len(third) != len(set(third)):
continue
if sorted(f) == sorted(third):
print(f + f[::-1] + third)
print(int(f) + int(f[::-1]) + int(third))
Edited on December 7, 2023, 2:32 pm
|
Posted by Larry
on 2023-12-03 12:28:14 |