login
Describe previous term from the right (method B - initial term is 7).
3

%I #21 Oct 14 2016 08:12:15

%S 7,71,1171,117112,21127112,211271211221,112212211171211221,

%T 1122122111711322112212,21112212223112711322112212,

%U 21112212223112712112312311221321

%N Describe previous term from the right (method B - initial term is 7).

%C Method B = 'digit'-indication followed by 'frequency'.

%H Reinhard Zumkeller, <a href="/A022518/b022518.txt">Table of n, a(n) for n = 0..21</a>

%e The term after 1171 is obtained by saying "1 once, 7 once, 1 twice", which gives 117112.

%t split[n_]:=Split[Reverse[IntegerDigits[n]]];

%t list1[n_]:=List/@Length/@split[n];riffle1[n_]:=Riffle[split[n],list1[n]];

%t tab[n_]:=Table[i,{i,1,2*Length[list1[n]],2}];

%t list2[n_]:=Append[riffle1[n][[#]],riffle1[n][[#+1]]]&/@tab[n];

%t flat[n_]:=Flatten/@list2[n];riffle2[n_]:=Riffle[First/@flat[n],Last/@flat[n]];

%t a[1]=7;a[n_]:=FromDigits[riffle2[a[n-1]]];Array[a,10] (* or *)

%t a[1]=7;a[n_]:=FromDigits[Flatten[Replace[Replace[Replace[Split[Reverse[IntegerDigits[

%t a[n-1]]]],{x_,y_}-> {x,Length[{x,y}]},{1}],{x_,y_,z_}-> {x,Length[{x,y,z}]},{1}],{x_}-> {x,Length[{x}]},{1}]]];Array[a,10] (* _Ivan N. Ianakiev_, Oct 07 2016 *)

%o (Haskell)

%o import Data.List (group, transpose)

%o a022518 n = a022518_list !! n

%o a022518_list = 7 : f [7] :: [Integer] where

%o f xs = (read $ concatMap show ys) : f ys where

%o ys = concat $ transpose [map head zss, map length zss]

%o zss = reverse $ group xs

%o -- _Reinhard Zumkeller_, Jan 26 2014

%Y Cf. A022481, A022488, A022514, A022515, A022516, A022517, A022519, A022520.

%K nonn,base,easy,nice

%O 0,1

%A _N. J. A. Sloane_

%E More terms from _Erich Friedman_

%E Corrected from 8th term by _Patrick De Geest_, Jun 15 1999