A140057 Numbers such that each decimal digit d (for all d in the range 1 <= d <= 9) occurs only in runs of length exactly d.
1, 22, 122, 221, 333, 1221, 1333, 3331, 4444, 13331, 14444, 22122, 22333, 33322, 44441, 55555, 122122, 122333, 133322, 144441, 155555, 221221, 221333, 223331, 224444, 333122, 333221, 444422, 555551, 666666, 1221221, 1221333, 1223331
Offset: 1
Links
- Robert G. Wilson v, Table of n, a(n) for n = 1..8032
Programs
-
Mathematica
(* first do *) Needs["Combinatorica`"] (* then *) f[n_] := Block[{ pa=Partitions@ n, len = PartitionsP@ n, s, lst, lmt}, s = Select[Range@len, pa[[ #, 1]] < 10 &]; lst=Take[pa, {s[[1]], -1}]; lst = Flatten[ DistinctPermutations /@ lst, 1]; lmt = Length@ lst; While[lmt != 0, If[ Split[lst[[lmt]]] != Partition[lst[[lmt]], 1], lst = Delete[lst, lmt]]; lmt-- ]; Sort@ (FromDigits /@ Flatten /@ (lst /. {x_Integer -> Table[x, {x}]}))] (* Robert G. Wilson v, May 25 2008 *) Select[Range[1250000],AllTrue[Split[IntegerDigits[#]],Length[#] == #[[1]]&]&] (* The program uses the AllTrue function from Mathematica version 10 *) (* Harvey P. Dale, Aug 04 2019 *)
Extensions
Definition expanded by N. J. A. Sloane, May 20 2008
Comments