A351877 Nonnegative integers whose trajectory under iteration of taking the absolute value of the alternating sum of the cubes of the digits includes zero.
0, 11, 22, 33, 44, 55, 58, 66, 77, 85, 88, 99, 110, 135, 138, 142, 179, 220, 232, 241, 256, 267, 284, 328, 330, 345, 346, 387, 396, 429, 440, 464, 482, 486, 531, 543, 550, 580, 587, 643, 652, 660, 684, 693, 762, 770, 783, 785, 808, 823, 831, 849, 850, 868, 880, 924, 948, 971, 990
Offset: 1
Examples
346 is a term of the sequence since: 346->179->387->142->55->0. 8 is not a term since: 8->512->132->18->511->125->118->512 (we reached a loop of length 6 starting with 512).
Programs
-
Mathematica
Select[Range[10000],FixedPoint[Abs[Sum[(-1)^(n + 1)*Part[IntegerDigits[#]^3, n], {n, 1,Length[IntegerDigits[#]]}]] &, #, 30] == 0 &]
-
PARI
f(n) = my(d=digits(n)); abs(sum(k=1, #d, (-1)^k*d[k]^3)); \\ A351985 already(m, v) = {for (i=1, #v, if (v[i] == m, return (1)););} isok(m) = {my(v=[]); while (m=f(m), if (already(m, v), return(0)); v = concat(v, m);); return(1);} \\ Michel Marcus, Feb 27 2022
-
Python
def happyish_function(number, base: int = 10): total = 0 times = 0 while number > 0: total += pow(-1, times) * pow(abs(number) % base, 3) number = abs(number) // base times += 1 return abs(total) def is_happyish(number: int) -> bool: seen_numbers = set() while number > 0 and number not in seen_numbers: seen_numbers.add(number) number = happyish_function(number) return number == 0 print([k for k in range(1000) if is_happyish(k)])
Comments