login
A022518
Describe previous term from the right (method B - initial term is 7).
3
7, 71, 1171, 117112, 21127112, 211271211221, 112212211171211221, 1122122111711322112212, 21112212223112711322112212, 21112212223112712112312311221321
OFFSET
0,1
COMMENTS
Method B = 'digit'-indication followed by 'frequency'.
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 0..21
EXAMPLE
The term after 1171 is obtained by saying "1 once, 7 once, 1 twice", which gives 117112.
MATHEMATICA
split[n_]:=Split[Reverse[IntegerDigits[n]]];
list1[n_]:=List/@Length/@split[n]; riffle1[n_]:=Riffle[split[n], list1[n]];
tab[n_]:=Table[i, {i, 1, 2*Length[list1[n]], 2}];
list2[n_]:=Append[riffle1[n][[#]], riffle1[n][[#+1]]]&/@tab[n];
flat[n_]:=Flatten/@list2[n]; riffle2[n_]:=Riffle[First/@flat[n], Last/@flat[n]];
a[1]=7; a[n_]:=FromDigits[riffle2[a[n-1]]]; Array[a, 10] (* or *)
a[1]=7; a[n_]:=FromDigits[Flatten[Replace[Replace[Replace[Split[Reverse[IntegerDigits[
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 *)
PROG
(Haskell)
import Data.List (group, transpose)
a022518 n = a022518_list !! n
a022518_list = 7 : f [7] :: [Integer] where
f xs = (read $ concatMap show ys) : f ys where
ys = concat $ transpose [map head zss, map length zss]
zss = reverse $ group xs
-- Reinhard Zumkeller, Jan 26 2014
KEYWORD
nonn,base,easy,nice
EXTENSIONS
More terms from Erich Friedman
Corrected from 8th term by Patrick De Geest, Jun 15 1999
STATUS
approved