A (base ten) positive integer N (with non leading zeroes) such that each of the digits of N, with the exception of the first digit and the last digit, is less than the arithmetic mean of the two neighboring digits.
Arrange all the integers satisfying the above in strictly ascending order.
What is the 100th number?
Note:no 1-digit or 2-digit number qualifies, since there are not enough digits to test.
346
The first 100 such numbers are:
[100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 112, 113, 114, 115, 116, 117, 118, 119, 124, 125, 126, 127, 128, 129, 136, 137, 138, 139, 148, 149, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 211, 212, 213, 214, 215, 216, 217, 218, 219, 223, 224, 225, 226, 227, 228, 229, 235, 236, 237, 238, 239, 247, 248, 249, 259, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 322, 323, 324, 325, 326, 327, 328, 329, 334, 335, 336, 337, 338, 339, 346]
And I think 96433469 may be the largest.
----------
def test(n):
testlist = [int(i) for i in list(str(n))]
length = len(testlist)
if length < 3:
return False
for index in range(1, length-1):
if testlist[index] >= (testlist[index-1] + testlist[index+1])/2:
return False
return True
solutions = [0] ; due to zero based list so index will match up.
for i in range(347):
if test(i):
print(i)
solutions.append(i)
print(solutions[100])
solutions.pop(0)
print(len(solutions))
|
Posted by Larry
on 2024-01-03 11:56:12 |