n letters in the alphabet, maximum word length k, letter repetitions permitted. (future post repetitions not permitted.) how many distinct words are possible, including the empty string?
g(n,k) = sum(i=0, k, n^i)
(defining 0^0 = 1)
g(0,k) = 1 for all k. if empty alphabet, only the empty string possible.
g(1,k) = k+1 . unary strings of length up to k, including length 0.
g(2,k) = 2^(k+1) - 1
for(i=0, 10, print(i" ",g(2,i)))
0 1
1 3
2 7
3 15
4 31
5 63
6 127
7 255
8 511
9 1023
10 2047
for(i=0, 10, print(i" ",g(10,i)))
0 1
1 11
2 111
3 1111
4 11111
5 111111
6 1111111
7 11111111
8 111111111
9 1111111111
10 11111111111
k-digit repunits of base n:
g(n,k) = (n^(k+1) - 1) / (n-1)
if n != 1 (can this restriction be removed with cleverness?).
k = 4 is intriguing for inventing a Chinese or Korean style writing system: up to 4 radicals or jamo in a square block, with a convention for extracting their order, e.g., read top to bottom, left to right. padding or stretching if less than 4 items.
for(i=0, 27, x=g(i,4); print(i" "x" ",x-1))
0 1 0
1 5 4
2 31 30
3 121 120
4 341 340
5 781 780
6 1555 1554
7 2801 2800
8 4681 4680
9 7381 7380
10 11111 11110
11 16105 16104
12 22621 22620
13 30941 30940
14 41371 41370
15 54241 54240
16 69905 69904
17 88741 88740
18 111151 111150
19 137561 137560
20 168421 168420
21 204205 204204
22 245411 245410
23 292561 292560
24 346201 346200
25 406901 406900
26 475255 475254
27 551881 551880
g(4,k)-1 omits the empty string, reserving it to be a character (word) separator.
values g(n,k) <= 1000, 2 <= n, 2 <= k :
7 g(2,2)
13 g(3,2)
15 g(2,3)
21 g(4,2)
31 g(2,4)
31 g(5,2)
40 g(3,3)
43 g(6,2)
57 g(7,2)
63 g(2,5)
73 g(8,2)
85 g(4,3)
91 g(9,2)
111 g(10,2)
121 g(3,4)
127 g(2,6)
133 g(11,2)
156 g(5,3)
157 g(12,2)
183 g(13,2)
211 g(14,2)
241 g(15,2)
255 g(2,7)
259 g(6,3)
273 g(16,2)
307 g(17,2)
341 g(4,4)
343 g(18,2)
364 g(3,5)
381 g(19,2)
400 g(7,3)
421 g(20,2)
463 g(21,2)
507 g(22,2)
511 g(2,8)
553 g(23,2)
585 g(8,3)
601 g(24,2)
651 g(25,2)
703 g(26,2)
757 g(27,2)
781 g(5,4)
813 g(28,2)
820 g(9,3)
871 g(29,2)
931 g(30,2)
993 g(31,2)
OEIS A031973 if n = k.
No comments :
Post a Comment