%I #17 Feb 11 2024 22:28:56
%S 42,154,389,398,415,451,514,541,839,893,938,983,1045,1054,1126,1162,
%T 1216,1261,1344,1405,1434,1443,1450,1504,1540,1588,1612,1621,1669,
%U 1696,1858,1885,1966,2116,2161,2235,2253,2325,2352,2523,2532,2611,3089,3098,3144
%N Unhappy numbers which enter the cycle (4, 16, 37, 58, 89, 145, 42, 20) at 42.
%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/UnhappyNumber.html">Unhappy Number</a>.
%e 389 is such a number of height 2 because it enters the cycle at 42 in 2 steps: 389 -> 154 -> 42 -> 20 -> 4 -> 16 -> 37 -> 58 -> 89 -> 145 -> 42 -> ...
%p S:=proc(n) local Q,k,N,z; Q:=[n]; for k from 1 do N:=convert(Q[k],base,10); z:=sum(N['i']^2,'i'=1..nops(N)); if not member(z,Q) then Q:=[op(Q),z]; else Q:=[op(Q),z]; break; fi; od; return Q; end:
%p a:=[]: for i from 1 while nops(a)<30 do Q:=S(i); A:=Q[nops(Q)]; if A=42 then a:=[op(a),i] fi; od: print(op(a));
%Y Cf. A031177, A039943.
%K nonn,base
%O 1,1
%A _Martin Renner_, Jul 31 2011