A230107 Define a sequence by b(1)=n, b(k+1)=b(k)+(sum of digits of b(k)); a(n) is the number of steps needed to reach a term in A004207, or a(n) = -1 if the sequence never joins A004207.
0, 0, -1, 0, 52, -1, 11, 0, -1, 51, 50, -1, 49, 10, -1, 0, 48, -1, 9, 50, -1, 49, 0, -1, 47, 48, -1, 0, 8, -1, 49, 46, -1, 47, 48, -1, 45, 0, -1, 7, 46, -1, 47, 6, -1, 45, 44, -1, 0, 46, -1, 5, 5, -1, 45, 44, -1, 43, 4, -1, 4, 0, -1, 4, 44, -1, 43, 3, -1, 0
Offset: 0
Examples
For n=3, A016052 never meets A004207, so a(3) = -1. For n=5, A007618 meets A004207 at the 53rd term, 620, so a(5) = 53.
Programs
-
Haskell
import Data.Maybe (fromMaybe) a230107 = fromMaybe (-1) . f (10^5) 1 1 1 where f k i u j v | k <= 0 = Nothing | u < v = f (k - 1) (i + 1) (a062028 u) j v | u > v = f (k - 1) i u (j + 1) (a062028 v) | otherwise = Just j
-
Maple
read transforms; # to get digsum M:=2000; # f(s) returns the sequence k->k+digsum(k) starting at s f:=proc(s) global M; option remember; local n,k,s1; s1:=[s]; k:=s; for n from 1 to M do k:=k+digsum(k); s1:=[op(s1),k]; od: end; # g(s) returns (x,p), where x = first number in common between # f(1) and f(s), and p is the position where it occurred. # If f(1), f(s) are disjoint for M terms, returns (-1,-1) S1:=convert(f(1),set): g:=proc(s) global f,S1; local t1,p,S2,S3; S2:=convert(f(s),set); S3:= S1 intersect S2; t1:=min(S3); if (t1 = infinity) then RETURN(-1,-1); else member(t1,f(s),'p'); RETURN(t1,p-1); fi; end; [seq(g(n)[2],n=1..20)];
Comments