|
|
A022518
|
|
Describe previous term from the right (method B - initial term is 7).
|
|
3
|
|
|
|
OFFSET
|
0,1
|
|
COMMENTS
|
Method B = 'digit'-indication followed by 'frequency'.
|
|
LINKS
|
|
|
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
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn,base,easy,nice
|
|
AUTHOR
|
|
|
EXTENSIONS
|
|
|
STATUS
|
approved
|
|
|
|