A134640 Permutational numbers (numbers with k different digits in k-positional system).
0, 1, 2, 5, 7, 11, 15, 19, 21, 27, 30, 39, 45, 54, 57, 75, 78, 99, 108, 114, 120, 135, 141, 147, 156, 177, 180, 198, 201, 210, 216, 225, 228, 194, 198, 214, 222, 238, 242, 294, 298, 334, 346, 358, 366, 414, 422, 434, 446, 482, 486, 538, 542, 558, 566, 582, 586
Offset: 1
Examples
We build permutational numbers: a(1)=0 in unitary positional system we have only one digit 0 a(2)=1 because in binary positional system smaller number with two different digits is 01 = 1 a(3)=2 because in binary positional system bigger number with two different digits is 10 = 2 (binary system is over) a(4)=5 because smallest number in ternary system with 3 different digits is 012=5 a(5)=7 second number in ternary system with 3 different digits is 021=7 a(6)=11 third number in ternary system with 3 different digits is 102=11 a(7)=15 120=15 etc.
Links
- Reinhard Zumkeller, Rows n = 1..7 of triangle, flattened
Crossrefs
Programs
-
Haskell
import Data.List (permutations, sort) a134640 n k = a134640_tabf !! (n-1) !! (k-1) a134640_row n = sort $ map (foldr (\dig val -> val * n + dig) 0) $ permutations [0 .. n - 1] a134640_tabf = map a134640_row [1..] a134640_list = concat a134640_tabf -- Reinhard Zumkeller, Aug 29 2014
-
Mathematica
a = {}; b = {}; Do[AppendTo[b, n]; w = Permutations[b]; Do[j = FromDigits[w[[m]], n + 1]; AppendTo[a, j], {m, 1, Length[w]}], {n, 0, 5}]; a (*Artur Jasinski*) Flatten[Table[FromDigits[#,n]&/@Permutations[Range[0,n-1]],{n,5}]] (* Harvey P. Dale, Dec 09 2014 *)
-
Python
from itertools import permutations def fd(d, b): return sum(di*b**i for i, di in enumerate(d[::-1])) def row(n): return [fd(d, n) for d in permutations(range(n))] print([an for r in range(1, 6) for an in row(r)]) # Michael S. Branicky, Oct 21 2022
Extensions
Corrected indices in examples. Replaced dashes in comments by the word "to" - R. J. Mathar, Aug 26 2009
Comments