Determine the maximum value of 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 harmonic mean of the two neighboring digits.
*** For an extra challenge, solve this puzzle without the aid of a computer program.
DECLARE SUB build (n#)
DEFDBL A-Z
CLEAR , , 25000
CLS
DIM SHARED h(50), maxv, v
maxv = 1
FOR st = 1 TO 9
h(1) = st: v = st
build 2
NEXT
SUB build (n)
FOR tr = 1 TO 9
IF n = 2 THEN
h(n) = tr: vsave = v: v = v * 10 + tr
IF v > maxv THEN
maxv = v
FOR i = 1 TO n
PRINT h(i);
NEXT
PRINT
END IF
build n + 1
v = vsave
ELSE
IF h(n - 1) < 2 / (1 / h(n - 2) + 1 / tr) THEN
h(n) = tr: vsave = v: v = v * 10 + tr
IF v > maxv THEN
maxv = v
FOR i = 1 TO n
PRINT h(i);
NEXT
PRINT " "; v
END IF
build n + 1
v = vsave
END IF
END IF
NEXT
END SUB
finds as the highest:
976679
|
Posted by Charlie
on 2013-12-28 16:00:13 |