主题:数学黑洞6174化简版
数学黑洞6174:
一个四位数组成的最大四位数减最小四位数,会得到一个新四位数,把这个四位数重复刚刚的动作,最后一定会变成7641-1467=6174,将永远出不来。
证明这个观点。(不能是四位数全部相同的,如1111,3333)
化简版:
CLS
DIM a(4)
DO: INPUT n$: LOOP UNTIL LEN(n$) = 4
n = VAL(n$)
DO
p = 0
FOR i = 1 TO 4: a(i) = VAL(MID$(n$, i, 1)): NEXT i
FOR i = 1 TO 3: FOR j = i + 1 TO 4
IF a(i) < a(j) THEN SWAP a(i), a(j)
IF a(i) = a(j) THEN p = p + 1
NEXT j, i
IF p = 6 THEN PRINT "Error!": END
max = a(1) * 1000 + a(2) * 100 + a(3) * 10 + a(4): x = 4
WHILE a(x) = 0: x = x - 1: WEND: SWAP a(4), a(x)
min = a(4) * 1000 + a(3) * 100 + a(2) * 10 + a(1)
PRINT max; "-"; min; "="; max - min
n = max - min: n$ = LTRIM$(STR$(n))
s = s + 1
LOOP UNTIL n = 6174
PRINT s
END
一个四位数组成的最大四位数减最小四位数,会得到一个新四位数,把这个四位数重复刚刚的动作,最后一定会变成7641-1467=6174,将永远出不来。
证明这个观点。(不能是四位数全部相同的,如1111,3333)
化简版:
CLS
DIM a(4)
DO: INPUT n$: LOOP UNTIL LEN(n$) = 4
n = VAL(n$)
DO
p = 0
FOR i = 1 TO 4: a(i) = VAL(MID$(n$, i, 1)): NEXT i
FOR i = 1 TO 3: FOR j = i + 1 TO 4
IF a(i) < a(j) THEN SWAP a(i), a(j)
IF a(i) = a(j) THEN p = p + 1
NEXT j, i
IF p = 6 THEN PRINT "Error!": END
max = a(1) * 1000 + a(2) * 100 + a(3) * 10 + a(4): x = 4
WHILE a(x) = 0: x = x - 1: WEND: SWAP a(4), a(x)
min = a(4) * 1000 + a(3) * 100 + a(2) * 10 + a(1)
PRINT max; "-"; min; "="; max - min
n = max - min: n$ = LTRIM$(STR$(n))
s = s + 1
LOOP UNTIL n = 6174
PRINT s
END