Weight-Botchers

Suppose you have a balance scale and four weights of 1 unit, 2 units, 4 units and 8 units. How many different weights can you match? If you know binary arithmetic, it’s easy to see that you can match any weight up to fifteen units inclusive. With the object in the left-hand pan of the scale and the weights in the right-hand pan, these are the matches:

01 = 1
02 = 2
03 = 2+1
04 = 4
05 = 4+1
06 = 4+2
07 = 4+2+1
08 = 8
09 = 8+1
10 = 8+2
11 = 8+2+1
12 = 8+4
13 = 8+4+1
14 = 8+4+2
15 = 8+4+2+1

Balance scale


The weights that sum to n match the 1s in the digits of n in binary.

01 = 0001 in binary
02 = 0010 = 2
03 = 0011 = 2+1
04 = 0100 = 4
05 = 0101 = 4+1
06 = 0110 = 4+2
07 = 0111 = 4+2+1
08 = 1000 = 8
09 = 1001 = 8+1
10 = 1010 = 8+2
11 = 1011 = 8+2+1
12 = 1100 = 8+4
13 = 1101 = 8+4+1
14 = 1110 = 8+4+2
15 = 1111 = 8+4+2+1

But there’s another set of four weights that will match anything from 1 unit to 40 units. Instead of using powers of 2, you use powers of 3: 1, 3, 9, 27. But how would you match an object weighing 2 units using these weights? Simple. You put the object in the left-hand scale, the 3-weight in the right-hand scale, and then add the 1-weight to the left-hand scale. In other words, 2 = 3-1. Similarly, 5 = 9-3-1, 6 = 9-3 and 7 = 9-3+1. When the power of 3 is positive, it’s in the right-hand pan; when it’s negative, it’s in the left-hand pan.

This system is actually based on base 3 or ternary, which uses three digits, 0, 1 and 2. However, the relationship between ternary numbers and the sums of positive and negative powers of 3 is more complicated than the relationship between binary numbers and sums of purely positive powers of 2. See if you can work out how to derive the sums in the middle from the ternary numbers on the right:

01 = 1 = 1 in ternary
02 = 3-1 = 2
03 = 3 = 10
04 = 3+1 = 11
05 = 9-3-1 = 12
06 = 9-3 = 20
07 = 9-3+1 = 21
08 = 9-1 = 22
09 = 9 = 100
10 = 9+1 = 101
11 = 9+3-1 = 102
12 = 9+3 = 110
13 = 9+3+1 = 111
14 = 27-9-3-1 = 112
15 = 27-9-3 = 120
16 = 27-9-3+1 = 121
17 = 27-9-1 = 122
18 = 27-9 = 200
19 = 27-9+1 = 201
20 = 27-9+3-1 = 202
21 = 27-9+3 = 210
22 = 27-9+3+1 = 211
23 = 27-3-1 = 212
24 = 27-3 = 220
25 = 27-3+1 = 221
26 = 27-1 = 222
27 = 27 = 1000
28 = 27+1 = 1001
29 = 27+3-1 = 1002
30 = 27+3 = 1010
31 = 27+3+1 = 1011
32 = 27+9-3-1 = 1012
33 = 27+9-3 = 1020
34 = 27+9-3+1 = 1021
35 = 27+9-1 = 1022
36 = 27+9 = 1100
37 = 27+9+1 = 1101
38 = 27+9+3-1 = 1102
39 = 27+9+3 = 1110
40 = 27+9+3+1 = 1111

To begin understanding the sums, consider those ternary numbers containing only 1s and 0s, like n = 1011[3], which equals 31 in decimal. The sum of powers is straightforward, because all of them are positive and they’re easy to work out from the digits of n in ternary: 1011 = 1*3^3 + 0*3^2 + 1*3^1 + 1*3^0 = 27+3+1. Now consider n = 222[3] = 26 in decimal. Just as a decimal number consisting entirely of 9s is always 1 less than a power of 10, so a ternary number consisting entirely of 2s is always 1 less than a power of three:

999 = 1000 - 1 = 10^3 - 1 (decimal)
222 = 1000[3] - 1 (ternary) = 26 = 27-1 = 3^3 - 1 (decimal)

If a ternary number contains only 2s and is d digits long, it will be equal to 3^d – 1. But what about numbers containing a mixture of 2s, 1s and 0s? Well, all ternary numbers containing at least one 2 will have a negative power of 3 in the sum. You can work out the sum by using the following algorithm. Suppose the number is five digits long and the rightmost digit is digit #1 and the leftmost is digit #5:

01. i = 1, sum = 0, extra = 0, posi = true.
02. if posi = false, goto step 07.
03. if digit #i = 0, sum = sum + 0.
04. if digit #i = 1, sum = sum + 3^(i-1).
05. if digit #i = 2, sum = sum - 3^(i-1), extra = 3^5, posi = false.
06. goto step 10.
07. if digit #i = 0, sum = sum + 3^(i-1), extra = 0, posi = true.
08. if digit #i = 1, sum = sum - 3^(i-1).
09. if digit #i = 2, sum = sum + 0.
10. i = i+1. if i <= 5, goto step 2.
11. print sum + extra.

As the number of weights grows, the advantages of base 3 get bigger:

With 02 weights, base 3 reaches 04 and base 2 reaches 3: 04-3 = 1.
With 03 weights, base 3 reaches 13 and base 2 reaches 7: 13-7 = 6.
With 04 weights, 000040 - 0015 = 000025
With 05 weights, 000121 - 0031 = 000090
With 06 weights, 000364 - 0063 = 000301
With 07 weights, 001093 - 0127 = 000966
With 08 weights, 003280 - 0255 = 003025
With 09 weights, 009841 - 0511 = 009330
With 10 weights, 029524 - 1023 = 028501
With 11 weights, 088573 - 2047 = 086526
With 12 weights, 265720 - 4095 = 261625...

But what about base 4, or quaternary? With four weights of 1, 4, 16 and 64, representing powers of 4 from 4^0 to 4^3, you should be able to weigh objects from 1 to 85 units using sums of positive and negative powers. In fact, some weights can’t be matched. As you can see below, if n in base 4 contains a 2, it can’t be represented as a sum of positive and negative powers of 4. Nor can certain other numbers:

1 = 1 ← 1
2 has no sum = 2
3 = 4-1 ← 3
4 = 4 ← 10 in base 4
5 = 4+1 ← 11 in base 4
6 has no sum = 12 in base 4
7 has no sum = 13
8 has no sum = 20
9 has no sum = 21
10 has no sum = 22
11 = 16-4-1 ← 23
12 = 16-4 ← 30
13 = 16-4+1 ← 31
14 has no sum = 32
15 = 16-1 ← 33
16 = 16 ← 100
17 = 16+1 ← 101
18 has no sum = 102
19 = 16+4-1 ← 103
20 = 16+4 ← 110
21 = 16+4+1 ← 111
22 has no sum = 112
23 has no sum = 113
24 has no sum = 120
25 has no sum = 121
26 has no sum = 122
27 has no sum = 123
[...]

With a more complicated balance scale, it’s possible to use weights representing powers of base 4 and base 5 (use two pans on each arm of the scale instead of one, placing the extra pan at the midpoint of the arm). But with a standard balance scale, base 3 is the champion. However, there is a way to do slightly better than standard base 3. You do it by botching the weights. Suppose you have four weights of 1, 4, 10 and 28 (representing 1, 3+1, 9+1 and 27+1). There are some weights n you can’t match, but because you can match n-1 and n+1, you know what these unmatchable weights are. Accordingly, while weights of 1, 3, 9 and 27 can measure objects up to 40 units, weights of 1, 4, 10 and 28 can measure objects up to 43 units:

1 = 1 ← 1
2 has no sum = 2
3 = 4-1 ← 10 in base 3
4 = 4 ← 11 in base 3
5 = 4+1 ← 12 in base 3
6 = 10-4 ← 20
7 = 10-4+1 ← 21
8 has no sum = 22
9 = 10-1 ← 100
10 = 10 ← 101
11 = 10+1 ← 102
12 has no sum = 110
13 = 10+4-1 ← 111
14 = 10+4 ← 112
15 = 10+4+1 ← 120
16 has no sum = 121
17 = 28-10-1 ← 122
18 = 28-10 ← 200
19 = 28-10+1 ← 201
20 has no sum = 202
21 = 28-10+4-1 ← 210
22 = 28-10+4 ← 211
23 = 28-4-1 ← 212
24 = 28-4 ← 220
25 = 28-4+1 ← 221
26 has no sum = 222
27 = 28-1 ← 1000
28 = 28 ← 1001
29 = 28+1 ← 1002
30 has no sum = 1010
31 = 28+4-1 ← 1011
32 = 28+4 ← 1012
33 = 28+4+1 ← 1020
34 = 28+10-4 ← 1021
35 = 28+10-4+1 ← 1022
36 has no sum = 1100
37 = 28+10-1 ← 1101
38 = 28+10 ← 1102
39 = 28+10+1 ← 1110
40 = has no sum = 1111*
41 = 28+10+4-1 ← 1112
42 = 28+10+4 ← 1120
43 = 28+10+4+1 ← 1121


*N.B. 40 = 82-28-10-4, i.e. has a sum when another botched weight, 82 = 3^4+1, is used.

Advertisements

Zequality Now

Here are the numbers one to eight in base 2:

1, 10, 11, 100, 101, 110, 111, 1000…

Now see what happens when you count the zeroes:


1, 10[1], 11, 10[2]0[3], 10[4]1, 110[5], 111, 10[6]0[7]0[8]...

In base 2, the numbers one to eight contain exactly eight zeroes, that is, zerocount(1..8,b=2) = 8. But it doesn’t work out so exactly in base 3:


1, 2, 10[1], 11, 12, 20[2], 21, 22, 10[3]0[4], 10[5]1, 10[6]2, 110[7], 111, 112, 120[8], 121, 122, 20[9]0[10], 20[11]1, 20[12]2, 210[13], 211, 212, 220[14], 221, 222, 10[15]0[16]0[17], 10[18]0[19]1, 10[20]0[21]2, 10[22]10[23], 10[24]11, 10[25]12, 10[26]20[27], 10[28]21, 10[29]22, 110[30]0[31], 110[32]1, 110[33]2, 1110[34], 1111, 1112, 1120[35], 1121, 1122, 120[36]0[37], 120[38]1, 120[39]2, 1210[40], 1211, 1212, 1220[41], 1221, 1222, 20[42]0[43]0[44], 20[45]0[46]1, 20[47]0[48]2, 20[49]10[50], 20[51]11, 20[52]12, 20[53]20[54], 20[55]21, 20[56]22, 210[57]0[58], 210[59]1, 210[60]2, 2110[61], 2111, 2112, 2120[62], 2121, 2122, 220[63]0[64], 220[65]1, 220[66]2, 2210[67], 2211, 2212, 2220[68], 2221, 2222, 10[69]0[70]0[71]0[72], 10[73]0[74]0[75]1, 10[76]0[77]0[78]2, 10[79]0[80]10[81], 10[82]0[83]11, 10[84]0[85]12, 10[86]0[87]20[88]...

In base 3, 10020 = 87 and zerocount(1..87,b=3) = 88. And what about base 4? zerocount(1..1068,b=4) = 1069 (n=100,230 in base 4). After that, zerocount(1..16022,b=5) = 16023 (n=1,003,043 in base 5) and zerocount(1..284704,b=6) = 284,705 (n=10,034,024 in base 6).

The numbers are getting bigger fast and it’s becoming increasingly impractible to count the zeroes individually. What you need is an algorithm that will take any given n and work out how many zeroes are required to write the numbers 1 to n. The simplest way to do this is to work out how many times 0 has appeared in each position of the number. The 1s position is easy: you simply divide the number by the base and discard the remainder. For example, in base 10, take the number 25. The 0 must have appeared in the 1s position twice, for 10 and 20, so zerocount(1..25) = 25 \ 10 = 2. In 2017, the 0 must have appeared in the 1s position 201 times = 2017 \ 10. And so on.

It gets a little trickier for the higher positions, the 10s, 100s, 1000s and so on, but the same basic principle applies. And so you can easily create an algorithm that takes a number, n, and produces zerocount(1..n) in a particular base. With this algorithm, you can quickly find zerocount(1..n) >= n in higher bases:


zerocount(1..1000,b=2) = 1,000 (n=8)*
zerocount(1..10020,b=3) = 10,021 (n=87)
zerocount(1..100230,b=4) = 100,231 (n=1,068)
zerocount(1..1003042,b=5) = 1,003,043 (n=16,022)
zerocount(1..10034024,b=6) = 10,034,025 (n=284,704)
zerocount(1..100405550,b=7) = 100,405,551 (n=5,834,024)
zerocount(1..1004500236,b=8) = 1,004,500,237 (n=135,430,302)
zerocount(1..10050705366,b=9) = 10,050,705,367 (n=3,511,116,537)
zerocount(1..100559404366,b=10) = 100,559,404,367
zerocount(1..1006083A68919,b=11) = 1,006,083,A68,919 (n=3,152,738,985,031)*
zerocount(1..10066AA1430568,b=12) = 10,066,AA1,430,569 (n=107,400,330,425,888)
zerocount(1..1007098A8719B81,b=13) = 100,709,8A8,719,B81 (n=3,950,024,143,546,664)*
zerocount(1..10077C39805D81C7,b=14) = 1,007,7C3,980,5D8,1C8 (n=155,996,847,068,247,395)
zerocount(1..10080B0034AA5D16D,b=15) = 10,080,B00,34A,A5D,171 (n=6,584,073,072,068,125,453)
zerocount(1..10088DBE29597A6C77,b=16) = 100,88D,BE2,959,7A6,C77 (n=295,764,262,988,176,583,799)*
zerocount(1..10090C5309AG72CBB3F,b=17) = 1,009,0C5,309,AG7,2CB,B3G (n=14,088,968,131,538,370,019,982)
zerocount(1..10099F39070FC73C1G73,b=18) = 10,099,F39,070,FC7,3C1,G75 (n=709,394,716,006,812,244,474,473)
zerocount(1..100A0DC1258614CA334EB,b=19) = 100,A0D,C12,586,14C,A33,4EC (n=37,644,984,315,968,494,382,106,708)
zerocount(1..100AAGDEEB536IBHE87006,b=20) = 1,00A,AGD,EEB,536,IBH,E87,008 (n=2,099,915,447,874,594,268,014,136,006)

And you can also easily find the zequal numbers, that is, the numbers n for which, in some base, zerocount(1..n) exactly equals n:


zerocount(1..1000,b=2) = 1,000 (n=8)
zerocount(1..1006083A68919,b=11) = 1,006,083,A68,919 (n=3,152,738,985,031)
zerocount(1..1007098A8719B81,b=13) = 100,709,8A8,719,B81 (n=3,950,024,143,546,664)
zerocount(1..10088DBE29597A6C77,b=16) = 100,88D,BE2,959,7A6,C77 (n=295,764,262,988,176,583,799)
zerocount(1..100CCJFFAD4MI409MI0798CJB3,b=24) = 10,0CC,JFF,AD4,MI4,09M,I07,98C,JB3 (n=32,038,681,563,209,056,709,427,351,442,469,835)
zerocount(1..100DDL38CIO4P9K0AJ7HK74EMI7L,b=26) = 1,00D,DL3,8CI,O4P,9K0,AJ7,HK7,4EM,I7L (n=160,182,333,966,853,031,081,693,091,544,779,177,187)
zerocount(1..100EEMHG6OE8EQKO0BF17LCCIA7GPE,b=28) = 100,EEM,HG6,OE8,EQK,O0B,F17,LCC,IA7,GPE (n=928,688,890,453,756,699,447,122,559,347,771,300,777,482)
zerocount(1..100F0K7MQO6K9R1S616IEEL2JRI73PF,b=29) = 1,00F,0K7,MQO,6K9,R1S,616,IEE,L2J,RI7,3PF (n=74,508,769,042,363,852,559,476,397,161,338,769,391,145,562)
zerocount(1..100G0LIL0OQLF2O0KIFTK1Q4DC24HL7BR,b=31) = 100,G0L,IL0,OQL,F2O,0KI,FTK,1Q4,DC2,4HL,7BR (n=529,428,987,529,739,460,369,842,168,744,635,422,842,585,510,266)
zerocount(1..100H0MUTQU3A0I5005WL2PD7T1ASW7IV7NE,b=33) = 10,0H0,MUT,QU3,A0I,500,5WL,2PD,7T1,ASW,7IV,7NE (n=4,262,649,311,868,962,034,947,877,223,846,561,239,424,294,726,563,632)
zerocount(1..100HHR387RQHK9OP6EDBJEUDAK35N7MN96LB,b=34) = 100,HHR,387,RQH,K9O,P6E,DBJ,EUD,AK3,5N7,MN9,6LB (n=399,903,937,958,473,433,782,862,763,628,747,974,628,490,691,628,136,485)
zerocount(1..100IISLI0CYX2893G9E8T4I7JHKTV41U0BKRHT,b=36) = 10,0II,SLI,0CY,X28,93G,9E8,T4I,7JH,KTV,41U,0BK,RHT (n=3,831,465,379,323,568,772,890,827,210,355,149,992,132,716,389,119,437,755,185)
zerocount(1..100LLX383BPWE[40]ZL0G1M[40]1OX[39]67KOPUD5C[40]RGQ5S6W9[36],b=42) = 10,0LL,X38,3BP,WE[40],ZL0,G1M,[40]1O,X[39]6,7KO,PUD,5C[40],RGQ,5S6,W9[36] (n=6,307,330,799,917,244,669,565,360,008,241,590,852,337,124,982,231,464,556,869,653,913,711,854)
zerocount(1..100MMYPJ[38]14KDV[37]OG[39]4[42]X75BE[39][39]4[43]CK[39]K36H[41]M[37][43]5HIWNJ,b=44) = 1,00M,MYP,J[38]1,4KD,V[37]O,G[39]4,[42]X7,5BE,[39][39]4,[43]CK,[39]K3,6H[41],M[37][43],5HI,WNJ (n=90,257,901,046,284,988,692,468,444,260,851,559,856,553,889,199,511,017,124,021,440,877,333,751,943)
zerocount(1..100NN[36]3813[38][37]16F6MWV[41]UBNF5FQ48N0JRN[40]E76ZOHUNX2[42]3[43],b=46) = 100,NN[36],381,3[38][37],16F,6MW,V[41]U,BNF,5FQ,48N,0JR,N[40]E,76Z,OHU,NX2,[42]3[43] (n=1,411,636,908,622,223,745,851,790,772,948,051,467,006,489,552,352,013,745,000,752,115,904,961,213,172,605)
zerocount(1..100O0WBZO9PU6O29TM8Y0QE3I[37][39]A7E4YN[44][42]70[44]I[46]Z[45][37]Q2WYI6,b=47) = 1,00O,0WB,ZO9,PU6,O29,TM8,Y0Q,E3I,[37][39]A,7E4,YN[44],[42]70,[44]I[46],Z[45][37],Q2W,YI6 (n=182,304,598,281,321,725,937,412,348,242,305,189,665,300,088,639,063,301,010,710,450,793,661,266,208,306,996)
zerocount(1..100PP[39]37[49]NIYMN[43]YFE[44]TDTJ00EAEIP0BIDFAK[46][36]V6V[45]M[42]1M[46]SSZ[40],b=50) = 1,00P,P[39]3,7[49]N,IYM,N[43]Y,FE[44],TDT,J00,EAE,IP0,BID,FAK,[46][36]V,6V[45],M[42]1,M[46]S,SZ[40] (n=444,179,859,561,011,965,929,496,863,186,893,220,413,478,345,535,397,637,990,204,496,296,663,272,376,585,291,071,790)
zerocount(1..100Q0Y[46][44]K[49]CKG[45]A[47]Z[43]SPZKGVRN[37]2[41]ZPP[36]I[49][37]EZ[38]C[44]E[46]00CG[38][40][48]ROV,b=51) = 10,0Q0,Y[46][44],K[49]C,KG[45],A[47]Z,[43]SP,ZKG,VRN,[37]2[41],ZPP,[36]I[49],[37]EZ,[38]C[44],E[46]0,0CG,[38][40][48],ROV (n=62,191,970,278,446,971,531,566,522,791,454,395,351,613,891,150,548,291,266,262,575,754,206,359,828,753,062,692,619,547)
zerocount(1..100QQ[40]TL[39]ZA[49][41]J[41]7Q[46]4[41]66A1E6QHHTM9[44]8Z892FRUL6V[46]1[38][41]C[40][45]KB[39],b=52) = 100,QQ[40],TL[39],ZA[49],41]J[41],7Q[46],4[41]6,6A1,E6Q,HHT,M9[44],8Z8,92F,RUL,6V[46],1[38][41],C[40][45],KB[39] (n=8,876,854,501,927,007,077,802,489,292,131,402,136,556,544,697,945,824,257,389,527,114,587,644,068,732,794,430,403,381,731)
zerocount(1..100S0[37]V[53]Y6G[51]5J[42][38]X[40]XO[38]NSZ[42]XUD[47]1XVKS[52]R[39]JAHH[49][39][50][54]5PBU[42]H3[45][46]DEJ,b=55) = 100,S0[37],V[53]Y,6G[51],5J[42],[38]X[40],XO[38],NSZ,[42]XU,D[47]1,XVK,S[52]R,[39]JA,HH[49],[39][50][54],5PB,U[42]H,3[45][46],DEJ (n=28,865,808,580,366,629,824,612,818,017,012,809,163,332,327,132,687,722,294,521,718,120,736,868,268,650,080,765,802,786,141,387,114)

Autonomata

“Describe yourself.” You can say it to people. And you can say it to numbers too. For example, here’s the number 3412 describing the positions of its own digits, starting at 1 and working upward:


3412 – the 1 is in the 3rd position, the 2 is in the 4th position, the 3 is in the 1st position, and the 4 is in the 2nd position.

In other words, the positions of the digits 1 to 4 of 3412 recreate its own digits:


3412 → (3,4,1,2) → 3412

The number 3412 describes itself – it’s autonomatic (from Greek auto, “self” + onoma, “name”). So are these numbers:


1
21
132
2143
52341
215634
7243651
68573142
321654798

More precisely, they’re panautonomatic numbers, because they describe the positions of all their own digits (Greek pan or panto, “all”). But what if you use the positions of only, say, the 1s or the 3s in a number? In base ten, only one number describes itself like that: 1. But we’re not confined to base 10. In base 2, the positions of the 1s in 110 (= 6) are 1 and 10 (= 2). So 110 is monautonomatic in binary (Greek mono, “single”). 10 is also monautonomatic in binary, if the digit being described is 0: it’s in 2nd position or position 10 in binary. These numbers are monoautonomatic in binary too:


110100 = 52 (digit = 1)
10100101111 = 1327 (d=0)

In 110100, the 1s are in 1st, 2nd and 4th position, or positions 1, 10, 100 in binary. In 10100101111, the 0s are in 2nd, 4th, 5th and 7th position, or positions 10, 100, 101, 111 in binary. Here are more monautonomatic numbers in other bases:


21011 in base 4 = 581 (digit = 1)
11122122 in base 3 = 3392 (d=2)
131011 in base 5 = 5131 (d=1)
2101112 in base 4 = 9302 (d=1)
11122122102 in base 3 = 91595 (d=2)
13101112 in base 5 = 128282 (d=1)
210111221 in base 4 = 148841 (d=1)

For example, in 131011 the 1s are in 1st, 3rd, 5th and 6th position, or positions 1, 3, 10 and 11 in quinary. But these numbers run out quickly and the only monautonomatic number in bases 6 and higher is 1. However, there are infinitely long monoautonomatic integer sequences in all bases. For example, in binary this sequence at the Online Encyclopedia of Integer Sequences describes itself using the positions of its 1s:


A167502: 1, 10, 100, 111, 1000, 1001, 1010, 1110, 10001, 10010, 10100, 10110, 10111, 11000, 11010, 11110, 11111, 100010, 100100, 100110, 101001, 101011, 101100, 101110, 110000, 110001, 110010, 110011, 110100, 111000, 111001, 111011, 111101, 11111, …

In base 10, it looks like this:


A167500: 1, 2, 4, 7, 8, 9, 10, 14, 17, 18, 20, 22, 23, 24, 26, 30, 31, 34, 36, 38, 41, 43, 44, 46, 48, 49, 50, 51, 52, 56, 57, 59, 61, 62, 63, 64, 66, 67, 68, 69, 70, 71, 75, 77, 80, 83, 86, 87, 89, 91, 94, 95, 97, 99, 100, 101, 103, 104, 107, 109, 110, 111, 113, 114, 119, 120, 124, … (see A287515 for a similar sequence using 0s)

In any base, you can find some sequence of integers describing the positions of any of the digits in that base – for example, the 1s or the 7s. But the numbers in the sequence get very large very quickly in higher bases. For example, here are some opening sequences for the digits 0 to 9 in base 10:


3, 10, 1111110, … (d=0)
1, 3, 10, 200001, … (d=1)
3, 12, 100000002, … (d=2)
2, 3, 30, 10000000000000000000000003, … (d=3)
2, 4, 14, 1000000004, … (d=4)
2, 5, 105, … (d=5)
2, 6, 1006, … (d=6)
2, 7, 10007, … (d=7)
2, 8, 100008, … (d=8)
2, 9, 1000009, … (d=9)

In the sequence for d=0, the first 0 is in the 3rd position, the second 0 is in the 10th position, and the third 0 is in the 1111110th position. That’s why I’ve haven’t written the next number – it’s 1,111,100 digits long (= 1111110 – 10). But it’s theoretically possible to write the number. In the sequence for d=3, the next number is utterly impossible to write, because it’s 9,999,999,999,999,999,999,999,973 digits long (= 10000000000000000000000003 – 30). In the sequence for d=5, the next number is this:


1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005 (100 digits long = 105 – 5).

And in fact there are an infinite number of such sequences for any digit in any base – except for d=1 in binary. Why is binary different? Because 1 is the only digit that can start a number in that base. With 0, you can invent a sequence starting like this:


111, 1110, 1111110, …

Or like this:


1111, 11111111110, …

Or like this:


11111, 1111111111111111111111111111110, …

And so on. But with 1, there’s no room for manoeuvre.

Square on a Three String

222 A.D. was the year in which the Emperor Heliogabalus was assassinated by his own soldiers. Exactly 1666 years later, the Anglo-Dutch classicist Sir Lawrence Alma-Tadema exhibited his painting The Roses of Heliogabalus (1888). I suggested in “Roses Are Golden” that Alma-Tadema must have chosen the year as deliberately as he chose the dimensions of his canvas, which, at 52″ x 84 1/8“, is an excellent approximation to the golden ratio.

But did Alma-Tadema know that lines at 0º and 222º divide a circle in the golden ratio? He could easily have done, just as he could easily have known that 222 precedes the 48th prime, 223. But it is highly unlikely that he knew that 223 yields a magic square whose columns, rows and diagonals all sum to 222. To create the square, simply list the 222 multiples of the reciprocal 1/223 in base 3, or ternary. The digits of the reciprocal repeat after exactly 222 digits and its multiples begin and end like this:

001/223 = 0.00001002102101021212111012022211122022... in base 3
002/223 = 0.00002011211202120201222101122200021121...
003/223 = 0.00010021021010212121110120222111220221...
004/223 = 0.00011100200112011110221210022100120020...
005/223 = 0.00012110002220110100102222122012012120...

[...]

218/223 = 0.22210112220002112122120000100210210102... in base 3
219/223 = 0.22211122022110211112001012200122102202...
220/223 = 0.22212201201212010101112102000111002001...
221/223 = 0.22220211011020102021000121100022201101...
222/223 = 0.22221220120121201010111210200011100200...

Each column, row and diagonal of ternary digits sums to 222. Here is the full n/223 square represented with 0s in grey, 1s in white and 2s in red:

(Click for larger)


It isn’t difficult to see that the white squares are mirror-symmetrical on a horizontal axis. Here is the symmetrical pattern rotated by 90º:

(Click for larger)


But why should the 1s be symmetrical? This isn’t something special to 1/223, because it happens with prime reciprocals like 1/7 too:

1/7 = 0.010212... in base 3
2/7 = 0.021201...
3/7 = 0.102120...
4/7 = 0.120102...
5/7 = 0.201021...
6/7 = 0.212010...

And you can notice something else: 0s mirror 2s and 2s mirror 0s. A related pattern appears in base 10:

1/7 = 0.142857...
2/7 = 0.285714...
3/7 = 0.428571...
4/7 = 0.571428...
5/7 = 0.714285...
6/7 = 0.857142...

The digit 1 in the decimal digits of n/7 corresponds to the digit 8 in the decimal digits of (7-n)/7; 4 corresponds to 5; 2 corresponds to 7; 8 corresponds to 1; 5 corresponds to 4; and 7 corresponds to 2. In short, if you’re given the digits d1 of n/7, you know the digits d2 of (n-7)/7 by the rule d2 = 9-d1.

Why does that happen? Examine these sums:

 1/7 = 0.142857142857142857142857142857142857142857...
+6/7 = 0.857142857142857142857142857142857142857142...
 7/7 = 0.999999999999999999999999999999999999999999... = 1.0

 2/7 = 0.285714285714285714285714285714285714285714...
+5/7 = 0.714285714285714285714285714285714285714285...
 7/7 = 0.999999999999999999999999999999999999999999... = 1.0

 3/7 = 0.428571428571428571428571428571428571428571...
+4/7 = 0.571428571428571428571428571428571428571428...
 7/7 = 0.999999999999999999999999999999999999999999... = 1.0

And here are the same sums in ternary (where the first seven integers are 1, 2, 10, 11, 12, 20, 21):

  1/21 = 0.010212010212010212010212010212010212010212...
+20/21 = 0.212010212010212010212010212010212010212010...
 21/21 = 0.222222222222222222222222222222222222222222... = 1.0

  2/21 = 0.021201021201021201021201021201021201021201...
+12/21 = 0.201021201021201021201021201021201021201021...
 21/21 = 0.222222222222222222222222222222222222222222... = 1.0

 10/21 = 0.102120102120102120102120102120102120102120...
+11/21 = 0.120102120102120102120102120102120102120102...
 21/21 = 0.222222222222222222222222222222222222222222... = 1.0

Accordingly, in base b with the prime p, the digits d1 of n/p correspond to the digits (p-n)/p by the rule d2 = (b-1)-d1. This explains why the 1s mirror themselves in ternary: 1 = 2-1 = (3-1)-1. In base 5, the 2s mirror themselves by the rule 2 = 4-2 = (5-1) – 2. In all odd bases, some digit will mirror itself; in all even bases, no digit will. The mirror-digit will be equal to (b-1)/2, which is always an integer when b is odd, but never an integer when b is even.

Here are some more examples of the symmetrical patterns found in odd bases:

Patterns of 1s in 1/19 in base 3


Patterns of 6s in 1/19 in base 13


Patterns of 7s in 1/19 in base 15


Elsewhere other-posted:

Roses Are Golden — more on The Roses of Heliogabalus (1888)
Three Is The Key — more on the 1/223 square

T4K1NG S3LF13S

It’s like watching a seed grow. You take a number and count how many 0s it contains, then how many 1s, how many 2s, 3s, 4s and so on. Then you create a new number by writing the count of each digit followed by the digit itself. Then you repeat the process with the new number.

Here’s how it works if you start with the number 1:

1

The count of digits is one 1, so the new number is this:

→ 11

The count of digits for 11 is two 1s, so the next number is:

→ 21

The count of digits for 21 is one 1, one 2, so the next number is:

→ 1112

The count of digits for 1112 is three 1s, one 2, so the next number is:

→ 3112

The count of digits for 3112 is two 1s, one 2, one 3, so the next number is:

→ 211213

What happens after that? Here are the numbers as a sequence:

1 → 11 → 21 → 1112 → 3112 → 211213 → 312213 → 212223 → 114213 → 31121314 → 41122314 → 31221324 → 21322314

That’s all you need, because something interesting happens with 21322314. The digit count is two 1s, three 2s, two 3s, one 4, so the next number is:

→ 21322314

In other words, 21322314 is what might be called a self-descriptive number: it describes the count of its own digits. That’s why I think this procedure is like watching a seed grow. You start with the tiny seed of 1 and end in the giant oak of 21322314, whose factorization is 2 * 3^2 * 13 * 91121. But there are many more self-descriptive numbers in base ten and some of them are much bigger than 21322314. A047841 at the Online Encyclopedia of Integer Sequences lists all 109 of them (and calls them “autobiographical numbers”). Here are a few, starting with the simplest possible:

22 → two 2s → 22
10213223 → one 0, two 1s, three 2s, two 3s → 10213223
10311233 → one 0, three 1s, one 2, three 3s → 10311233
21322314 → two 1s, three 2s, two 3s, one 4 → 21322314
21322315 → two 1s, three 2s, two 3s, one 5 → 21322315
21322316 → two 1s, three 2s, two 3s, one 6 → 21322316*
1031223314 → one 0, three 1s, two 2s, three 3s, one 4 → 10
31223314
3122331415 → three 1s, two 2s, three 3s, one 4, one 5
→ 3122331415
3122331416 → three 1s, two 2s, three 3s, one 4, one 6
→ 3122331416*

*And for 21322317, 21322318, 21322319; 3122331417, 3122331418, 3122331419.


And here’s what happens when you seed a sequence with a number containing all possible digits in base ten:

1234567890 → 10111213141516171819 → 101111213141516171819 → 101211213141516171819 → 101112213141516171819

That final number is self-descriptive:

101112213141516171819 → one 0, eleven 1s, two 2s, one 3, one 4, one 5, one 6, one 7, one 8, one 9 → 101112213141516171819

So some numbers are self-descriptive and some start a sequence that ends in a self-descriptive number. But that doesn’t exhaust the possibilities. Some numbers are part of a loop:

103142132415 → 104122232415 → 103142132415
104122232415 → 103142132415 → 104122232415
1051421314152619 → 1061221324251619 → 1051421314152619…
5142131415261819 → 6122132425161819 → 5142131415261819
106142131416271819 → 107122132426171819 → 106142131416271819


10512223142518 → 10414213142518 → 10512213341518 → 10512223142518
51222314251718 → 41421314251718 → 51221334151718 →
51222314251718

But all that is base ten. What about other bases? In fact, nearly all self-descriptive numbers in base ten are also self-descriptive in other bases. An infinite number of other bases, in fact. 22 is a self-descriptive number for all b > 2. The sequence seeded with 1 is identical in all b > 4:

1 → 11 → 21 → 1112 → 3112 → 211213 → 312213 → 212223 → 114213 → 31121314 → 41122314 → 31221324 → 2132231421322314

In bases 2, 3 and 4, the sequence seeded with 1 looks like this:

1 → 11 → 101 → 10101 → 100111 → 1001001 → 1000111 → 11010011101001… (b=2) (1101001[2] = 105 in base 10)
1 → 11 → 21 → 1112 → 10112 → 1010112 → 2011112 → 10111221011122… (b=3) (1011122[3] = 854 in base 10)
1 → 11 → 21 → 1112 → 3112 → 211213 → 312213 → 212223 → 1110213 → 101011213 → 201111213 → 101112213101112213… (b=4) (101112213[4] = 71079 in base 10)

In base 2 there are only two self-descriptive numbers (and no loops):

111 → three 1s → 111… (b=2) (111 = 7 in base 10)
1101001 → three 0s, four 1s → 1101001… (b=2) (1101001 = 105 in base 10)

So if you apply the “count digits” procedure in base 2, all numbers, except 111, begin a sequence that ends in 1101001. Base 3 has a few more self-descriptive numbers and also some loops:

2222… (b >= 3)
10111 → one 0, four 1s → 10111… (b=3)
11112 → four 1s, one 2 → 11112
100101 → three 0s, three 1s → 100101… (b=3)
1011122 → one 0, four 1s, two 2s → 1011122… (b=3)
2021102 → two 0s, two 1s, three 2s → 2021102… (b=3)
10010122 → three 0s, three 1s, two 2s → 10010122


2012112 → 10101102 → 10011112 → 2012112
10011112 → 2012112 → 10101102 → 10011112
10101102 → 10011112 → 2012112 → 10101102

A question I haven’t been able to answer: Is there a base in which loops can be longer than these?

103142132415 → 104122232415 → 103142132415
10512223142518 → 10414213142518 → 10512213341518 → 10512223142518

A question I have been able to answer: What is the sequence when it’s seeded with the title of this blog-post? T4K1NGS3LF13S is a number in all bases >= 30 and its base-30 form equals 15,494,492,743,722,316,018 in base 10 (with the factorization 2 * 72704927 * 106557377767). If T4K1NGS3LF13S seeds a sequence in any b >= 30, the result looks like this:

T4K1NGS3LF13S → 2123141F1G1K1L1N2S1T → 813213141F1G1K1L1N1S1T → A1122314181F1G1K1L1N1S1T → B1221314181A1F1G1K1L1N1S1T → C1221314181A1B1F1G1K1L1N1S1T → D1221314181A1B1C1F1G1K1L1N1S1T → E1221314181A1B1C1D1F1G1K1L1N1S1T → F1221314181A1B1C1D1E1F1G1K1L1N1S1T → G1221314181A1B1C1D1E2F1G1K1L1N1S1T → F1321314181A1B1C1D1E1F2G1K1L1N1S1T → F1222314181A1B1C1D1E2F1G1K1L1N1S1T → E1421314181A1B1C1D1E2F1G1K1L1N1S1T → F1221324181A1B1C1D2E1F1G1K1L1N1S1T → E1421314181A1B1C1D1E2F1G1K1L1N1S1T

Block n Rule

One of my favourite integer sequences uses the formula n(i) = n(i-1) + digsum(n(i-1)), where digsum(n) sums the digits of n. In base 10, it goes like this:

1, 2, 4, 8, 16, 23, 28, 38, 49, 62, 70, 77, 91, 101, 103, 107, 115, 122, 127, 137, 148, 161, 169, 185, 199, 218, 229, 242, 250, 257, 271, 281, 292, 305, 313, 320, 325, 335, 346, 359, 376, 392, 406, 416, 427, 440, 448, 464, 478, 497, 517, 530, 538, 554, 568, 587, 607, 620, 628, 644, 658, 677, 697, 719, 736, 752, 766, 785, 805, 818, 835, 851, 865, 884, 904, 917, 934, 950, 964, 983, 1003…

Another interesting sequence uses the formula n(i) = n(i-1) + digprod(n(i-1)), where digprod(n) multiplies the digits of n (excluding 0). In base 10, it goes like this:

1, 2, 4, 8, 16, 22, 26, 38, 62, 74, 102, 104, 108, 116, 122, 126, 138, 162, 174, 202, 206, 218, 234, 258, 338, 410, 414, 430, 442, 474, 586, 826, 922, 958, 1318, 1342, 1366, 1474, 1586, 1826, 1922, 1958, 2318, 2366, 2582, 2742, 2854, 3174, 3258, 3498, 4362, 4506, 4626, 4914, 5058, 5258, 5658, 6858, 8778, 11914, 11950, 11995…

You can apply these formulae in other bases and it’s trivially obvious that the sequences rise most slowly in base 2, because you’re never summing or multiplying anything but the digit 1. However, there is a sequence for which base 2 is by far the best performer. It has the formula n(i) = n(i-1) + blockmult(n(i-1)), where blockmult(n) counts the lengths of distinct blocks of the same digit, including 0, then multiplies those lengths together. For example:

blockmult(3,b=2) = blockmult(11) = 2
blockmult(28,b=2) = blockmult(11100) = 3 * 2 = 6
blockmult(51,b=2) = blockmult(110011) = 2 * 2 * 2 = 8
blockmult(140,b=2) = blockmult(10001100) = 1 * 3 * 2 * 2 = 12
blockmult(202867,b=2) = blockmult(110001100001110011) = 2 * 3 * 2 * 4 * 3 * 2 * 2 = 576

The full sequence begins like this (numbers are represented in base 10, but the formula is being applied to their representations in binary):

1, 2, 3, 5, 6, 8, 11, 13, 15, 19, 23, 26, 28, 34, 37, 39, 45, 47, 51, 59, 65, 70, 76, 84, 86, 88, 94, 98, 104, 110, 116, 122, 126, 132, 140, 152, 164, 168, 171, 173, 175, 179, 187, 193, 203, 211, 219, 227, 245, 249, 259, 271, 287, 302, 308, 316, 332, 340, 342, 344, 350, 354, 360, 366, 372, 378, 382, 388, 404, 412, 436, 444, 460, 484, 500, 510, 518, 530, 538, 546, 555, 561, 579, 595, 603, 611, 635, 651, 657, 663, 669, 675, 681…

In higher bases, it rises much more slowly. This is base 3:

1, 2, 3, 4, 6, 7, 8, 10, 11, 12, 14, 16, 17, 19, 20, 21, 22, 24, 26, 29, 31, 33, 34, 35, 37, 39, 42, 44, 48, 49, 51, 53, 56, 58, 60, 61, 62, 64, 65, 66, 68, 70, 71, 73, 75, 77, 79, 82, 85, 89, 93, 95, 97, 98, 100, 101, 102, 103, 105, 107, 110, 114, 116, 120, 124, 127, 129, 131, 133, 137, 139, 141, 142, 143, 145, 146, 147, 149, 151, 152, 154, 156, 158, 160, 163…

And this is base 10:

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 90…

Note how, in bases 3 and 10, blockmult(n) often equals 1. In base 3, the sequence contains [141, 142, 143, 145]:

blockmult(141,b=3) = blockmult(12020) = 1 * 1 * 1 * 1 = 1
blockmult(142,b=3) = blockmult(12021) = 1 * 1 * 1 * 1 = 1
blockmult(143,b=3) = blockmult(12022) = 1 * 1 * 1 * 2 = 2

The formula also returns 1 much further along the sequence in base 3. For example, the 573809th number in the sequence, or n(573809), is 5775037 and blockmult(5775037) = blockmult(101212101212021) = 1^15 = 1. But in base 2, blockmult(n) = 1 is very rare. It happens three times at the beginning of the sequence:

1, 2, 3, 5, 6, 8, 11…

After that, I haven’t found any more examples of blockmult(n) = 1, although blockmult(n) = 2 occurs regularly. For example,

blockmult(n(100723)) = blockmult(44739241) = blockmult(10101010101010101010101001) = 2
blockmult(n(100724)) = blockmult(44739243) = blockmult(10101010101010101010101011) = 2
blockmult(n(100725)) = blockmult(44739245) = blockmult(10101010101010101010101101) = 2

Does the sequence in base 2 return another example of blockmult(n) = 1? The odds seem against it. For any given number of digits in base 2, there is only one number for which blockmult(n) = 1. For example: 1, 10, 101, 1010, 10101, 101010, 1010101… As the sequence increases, the percentage of these numbers becomes smaller and smaller. But the sequence is infinite, so who knows what happens in the end? Perhaps blockmult(n) = 1 occurs infinitely often.

Playing the Double Base

Here’s some mathematical nonsense:

10 > 12
100 > 122
1000 > 1222

How can 1000 > 1222? Well, it makes perfect sense in what you might call a double base. In this base, every number is identified by a unique string of digits, but the strings don’t behave as they do in a standard base.

To see how this double base works, first look at 9 in standard base 2. To generate the binary digits from right to left, you follow the procedure x mod 2 and x = x div 2, where (x mod 2) returns the remainder when x is divided by 2 and (x div 2) divides x by 2 and discards the remainder:

9 mod 2 = 1 → ...1
9 div 2 = 4
4 mod 2 = 0 → ..01
4 div 2 = 2
2 mod 2 = 0 → .001
2 div 2 = 1
1 mod 2 = 1 → 1001

So 9[b=10] = 1001[b=2]. To adapt the procedure to base 3, simply use x mod 3 and x = x div 3:

32 mod 3 = 2 → ...2
32 div 3 = 10
10 mod 3 = 1 → ..12
10 div 3 = 3
3 mod 3 = 0 → .012
3 div 3 = 1
1 mod 3 = 1 → 1012

So 32[b=10] = 1012[b=3].

But what happens if you mix bases and use (x mod 3) and (x div 2), like this?:

2 mod 3 = 2 → .2
2 div 2 = 1
1 mod 3 = 1 → 12

3 mod 3 = 0 → .0
3 div 2 = 1
1 mod 3 = 1 → 10

So 10 > 12, i.e. 10[b=3,2] > 12[b=3,2].

5 mod 3 = 2 → ..2
5 div 2 = 2
2 mod 3 = 2 → .22
2 div 2 = 1
1 mod 3 = 1 → 122

6 mod 3 = 0 → ..0
6 div 2 = 3
3 mod 3 = 0 → .00
3 div 2 = 1
1 mod 3 = 1 → 100

So 100 > 122.

11 mod 3 = 2 → ...2
11 div 2 = 5
5 mod 3 = 2 → ..22
5 div 2 = 2
2 mod 3 = 2 → .222
2 div 2 = 1
1 mod 3 = 1 → 1222

12 mod 3 = 0 → …0
12 div 2 = 6
6 mod 3 = 0 → ..00
6 div 2 = 3
3 mod 3 = 0 → .000
3 div 2 = 1
1 mod 3 = 1 → 1000

And 1000 > 1222. Here are numbers 1 to 32 in this double base:

1 = 1
12 = 2
10 = 3
121 = 4
122 = 5
100 = 6
101 = 7
1212 = 8
1210 = 9
1221 = 10
1222 = 11
1000 = 12
1001 = 13
1012 = 14
1010 = 15
12121 = 16
12122 = 17
12100 = 18
12101 = 19
12212 = 20
12210 = 21
12221 = 22
12222 = 23
10000 = 24
10001 = 25
10012 = 26
10010 = 27
10121 = 28
10122 = 29
10100 = 30
10101 = 31
121212 = 32

Given a number represented in this mixed base, how do you extract the underlying n? Suppose the number takes the form n = (digit[1]..digit[di]), where digit[1] is the first and leftmost digit and digit[di] the final and rightmost digit. Then this algorithm will extract n:

n = 1
for i = 2 to di
..n = n * 2
..while n mod 3 ≠ digit[i]
....n = n + 1
..endwhile
next i
print n

For example, suppose n = 12212[b=3,2]. Then di = 5 and the algorithm will work like this:

n = 1
n = n * 2 = 2.
2 mod 3 = 2 = digit[2]
2 * 2 = 4
4 mod 3 = 1 ≠ digit[3]
5 mod 3 = 2 = digit[3]
5 * 2 = 10
10 mod 3 = 1 = digit[4]
10 * 2 = 20
20 mod 3 = 2 = digit[5]

Therefore 12212[b=3,2] = 20[b=10].

Now try some more mathematical nonsense:

21 > 100
111 > 1,000
1,001 > 10,000
10,001 > 100,000

How can numbers with d digits be greater than numbers with d+1 digits? Easily. In this incremental base, the base adjusts itself as the digits are generated, like this:

5 mod 2 = 1 → .1
5 div 2 = 2
2 mod (2 + 1) = 2 mod 3 = 2 → 21

The first digit generated is 1, so the base increases to (2 + 1) = 3 for the second digit. Compare the procedure when n = 4:

4 mod 2 = 0 → ..0
4 div 2 = 2
2 mod 2 = 0 → .00
2 div 2 = 1
1 mod 2 = 1 → 100

So 21 > 100, because 4 is a power of 2 and all the digits generated by (x mod 2) are 0 except the final and leftmost. 2 + 0 = 2. Now try n = 33:

33 mod 2 = 1 → ...1
33 div 2 = 16
16 mod (2+1) = 16 mod 3 = 1 → ..11
16 div 3 = 5
5 mod (3+1) = 5 mod 4 = 1 → .111
5 div 4 = 1
1 mod (4+1) = 1 mod 5 = 1.

33[b=10] = 1111[b=2,3,4,5].

Here are numbers 1 to 60 in this incremental base (note how 21 > 100, 111 > 1000, 1001 > 10000 and 10001 > 100000):

1 = 1
10 = 2
11 = 3
100 = 4*
21 = 5*
110 = 6
101 = 7
1000 = 8*
111 = 9*
210 = 10
121 = 11
1100 = 12
201 = 13
1010 = 14
211 = 15
10000 = 16*
221 = 17
1110 = 18
1001 = 19*
2100 = 20
311 = 21
1210 = 22
321 = 23
11000 = 24
1101 = 25
2010 = 26
1011 = 27
10100 = 28
421 = 29
2110 = 30
1201 = 31
100000 = 32*
1111 = 33
2210 = 34
1021 = 35
11100 = 36
2001 = 37
10010 = 38
1211 = 39
21000 = 40
1121 = 41
3110 = 42
2101 = 43
12100 = 44
1311 = 45
3210 = 46
1221 = 47
110000 = 48
2201 = 49
11010 = 50
2011 = 51
20100 = 52
1321 = 53
10110 = 54
10001 = 55*
101000 = 56
2111 = 57
4210 = 58
1421 = 59
21100 = 60

And here are numbers 256 to 270 (Note how 8,421 > 202,100 > 100,000,000):

100000000 = 256*
11221 = 257
101110 = 258
32101 = 259
202100 = 260*
13311 = 261
41210 = 262
10321 = 263
1111000 = 264
24201 = 265
131010 = 266
23011 = 267
320100 = 268
8421 = 269*
52110 = 270

Extracting n from a number represented in this incremental base is trickier than for the double base using (x mod 3) and (x div 2). To see how to do it, examine 11221[b=incremental]. The fifth and rightmost digit is 1, so the base increases to (2 + 1) = 3 for the fourth digit, which is 2. The base increases to (3 + 2) = 5 for the third digit, which is 2 again. The base increases to (5 + 2) = 7 for the second digit, 1. But the first and rightmost digit, 1, represents (x div 7) mod (7 + 1 = 8). So n can be extracted like this:

digit[1] * 7 = 1 * 7 = 7
7 mod 7 = 0 ≠ digit[2]
8 mod 7 = 1 = digit[2]
8 * 5 = 40
40 mod 5 = 0 ≠ digit[3]
41 mod 5 = 1 ≠ digit[3]
42 mod 5 = 2 = digit[3]
42 * 3 = 126
126 mod 3 = 0 ≠ digit[4]
127 mod 3 = 1 ≠ digit[4]
128 mod 3 = 2 = digit[4]
128 * 2 = 256
256 mod 2 = 0 ≠ digit[5]
257 mod 2 = 1 = digit[5]

So 11221[b=8,7,5,3,2] = 257[b=10].

Now try 8421[b=incremental]. The fourth and rightmost digit is 1, so the base increases to (2 + 1) = 3 for the third digit, which is 2. The base increases to (3 + 2) = 5 for the second digit, 4. But the first and rightmost digit, 8, represents (x div 5) mod (5 + 4 = 9). So n can be extracted like this:

digit[1] * 5 = 8 * 5 = 40
40 mod 5 = 0 ≠ digit[2]
41 mod 5 = 1 ≠ digit[2]
42 mod 5 = 2 ≠ digit[2]
43 mod 5 = 3 ≠ digit[2]
44 mod 5 = 4 = digit[2]
44 * 3 = 132
132 mod 3 = 0 ≠ digit[3]
133 mod 3 = 1 ≠ digit[3]
134 mod 3 = 2 = digit[3]
134 * 2 = 268
268 mod 2 = 0 ≠ digit[4]
269 mod 2 = 1 = digit[4]

So 8421[b=9,5,3,2] = 269[b=10].

Summus

I’m interested in digit-sums and in palindromic numbers. Looking at one, I found the other. It started like this: 9^2 = 81 and 9 = 8 + 1, so digitsum(9^1) = digitsum(9^2). I wondered how long such a sequence of powers could be (excluding powers of 10). I quickly found that the digit-sum of 468 is equal to the digit-sum of its square and cube:

digsum(468) = digsum(219024) = digsum(102503232)

But I couldn’t find any longer sequence, although plenty of other numbers are similar to 468:

digsum(585) = digsum(342225) = digsum(200201625)
digsum(4680) = digsum(21902400) = digsum(102503232000)
digsum(5850) = digsum(34222500) = digsum(200201625000)
digsum(5851) = digsum(34234201) = digsum(200304310051)
digsum(5868) = digsum(34433424) = digsum(202055332032)
digsum(28845) = digsum(832034025) = digsum(24000021451125) […]
digsum(589680) = digsum(347722502400) = digsum(205045005215232000)

What about other bases? First came this sequence:

digsum(2) = digsum(11) (base = 3) (highest power = 2)

Then these:

digsum(4) = digsum(22) = digsum(121) (b=7) (highest power = 3)
digsum(8) = digsum(44) = digsum(242) = digsum(1331) (b=15) (hp=4)
digsum([16]) = digsum(88) = digsum(484) = digsum(2662) = digsum(14641) (b=31) (hp=5)

The pattern continues (a number between square brackets represents a single digit in the base):

digsum([32]) = digsum([16][16]) = digsum(8[16]8) = digsum(4[12][12]4) = digsum(28[12]82) = digsum(15[10][10]51) (b=63) (hp=6)
digsum([64]) = digsum([32][32]) = digsum([16][32][16]) = digsum(8[24][24]8) = digsum(4[16][24][16]4) = digsum(2[10][20][20][10]2) = digsum(16[15][20][15]61) (b=127) (hp=7)
digsum([128]) = digsum([64][64]) = digsum([32][64][32]) = digsum([16][48][48][16]) = digsum(8[32][48][32]8) = digsum(4[20][40][40][20]4) = digsum(2[12][30][40][30][12]2) = digsum(17[21][35][35][21]71) (b=255) (hp=8)
digsum([256]) = digsum([128][128]) = digsum([64][128][64]) = digsum([32][96][96][32]) = digsum([16][64][96][64][16]) = digsum(8[40][80][80][40]8) = digsum(4[24][60][80][60][24]4) = digsum(2[14][42][70][70][42][14]2) = digsum(18[28][56][70][56][28]81) (b=511) (hp=9)

After this, I looked at sequences in which n(i) = n(i-1) + digitsum(n(i-1)). How long could digitsum(n(i)) be greater than or equal to digitsum(n(i-1))? In base 10, I found these sequences:

1 (digitsum=1) → 2 → 4 → 8 → 16 (sum=7) (count=4) (base=10)
9 → 18 (sum=9) → 27 (s=9) → 36 (s=9) → 45 (s=9) → 54 (s=9) → 63 (s=9) → 72 (s=9) → 81 (s=9) → 90 (s=9) → 99 (s=18) → 117 (s=9) (c=11) (b=10)
801 (s=9) → 810 (s=9) → 819 (s=18) → 837 (s=18) → 855 (s=18) → 873 (s=18) → 891 (s=18) → 909 (s=18) → 927 (s=18) → 945 (s=18) → 963 (s=18) → 981 (s=18) → 999 (s=27) → 1026 (s=9) (c=13)

Base 2 does better:

1 → 10 (s=1) → 11 (s=2) → 101 (s=2) → 111 (s=3) → 1010 (s=2) (c=5) (b=2)
16 = 10000 (s=1) → 10001 (s=2) → 10011 (s=3) → 10110 (s=3) → 11001 (s=3) → 11100 (s=3) → 11111 (s=5) → 100100 (s=2) (c=7) (b=2)
962 = 1111000010 (s=5) → 1111000111 (s=7) → 1111001110 (s=7) → 1111010101 (s=7) → 1111011100 (s=7) → 1111100011 (s=7) → 1111101010 (s=7) → 1111110001 (s=7) → 1111111000 (s=7) → 1111111111 (s=10) → 10000001001 (s=3) (c=10) (b=2)
524047 = 1111111111100001111 (s=15) → 1111111111100011110 (s=15) → 1111111111100101101 (s=15) → 1111111111100111100 (s=15) → 1111111111101001011 (s=15) → 1111111111101011010 (s=15) → 1111111111101101001(s=15) → 1111111111101111000 (s=15) → 1111111111110000111 (s=15) → 1111111111110010110 (s=15) → 1111111111110100101 (s=15) → 1111111111110110100 (s=15) → 1111111111111000011 (s=15) → 1111111111111010010 (s=15) → 1111111111111100001 (s=15) → 1111111111111110000 (s=15) → 1111111111111111111 (s=19) → 10000000000000010010 (s=3) (c=17) (b=2)

The best sequence I found in base 3 is shorter than in base 10, but there are more sequences:

1 → 2 → 11 (s=2) → 20 (s=2) → 22 (s=4) → 110 (s=2) (c=5) (b=3)
31 = 1011 (s=3) → 1021 (s=4) → 1102 (s=4) → 1120 (s=4) → 1201 (s=4) → 1212 (s=6) → 2002 (s=4) (c=6) (b=3)
54 = 2000 (s=2) → 2002 (s=4) → 2020 (s=4) → 2101 (s=4) → 2112 (s=6) → 2202 (s=6) → 2222 (s=8) → 10021(s=4) (c=7) (b=3)
432 = 121000 (s=4) → 121011 (s=6) → 121101 (s=6) → 121121 (s=8) → 121220 (s=8) → 122012 (s=8) → 122111 (s=8) → 122210 (s=8) → 200002 (s=4) (c=8) (b=3)
648 = 220000 (s=4) → 220011 (s=6) → 220101 (s=6) → 220121 (s=8) → 220220 (s=8) → 221012 (s=8) → 221111 (s=8) → 221210 (s=8) → 222002 (s=8) → 222101 (s=8) → 222200 (s=8) → 222222 (s=12) → 1000102 (s=4) (c=12) (b=3)

And what about sequences in which digitsum(n(i)) is always greater than digitsum(n(i-1))? Base 10 is disappointing:

1 → 2 → 4 → 8 → 16 (sum=7) (count=4) (base=10)
50 (s=5) → 55 (s=10) → 65 (s=11) → 76 (s=13) → 89 (s=17) → 106 (s=7) (c=5) (b=10)

Some other bases do better:

2 = 10 (s=1) → 11 (s=2) → 101 (s=2) (c=2) (b=2)
4 = 100 (s=1) → 101 (s=2) → 111 (s=3) → 1010 (s=2) (c=3) (b=2)
240 = 11110000 (s=4) → 11110100 (s=5) → 11111001 (s=6) → 11111111 (s=8) → 100000111 (s=4) (c=4) (b=2)

1 → 2 → 11 (s=2) (c=2) (b=3)
19 = 201 (s=3) → 211 (s=4) → 222 (s=6) → 1012 (s=4) (c=3) (b=3)
58999 = 2222221011 (s=15) → 2222221201 (s=16) → 2222222022 (s=18) → 2222222222 (s=20) → 10000000201 (s=4) (c=4) (b=3)

1 → 2 → 10 (s=1) (c=2) (b=4)
4 = 10 (s=1) → 11 (s=2) → 13 (s=4) → 23 (s=5) → 100 (s=1) (c=4) (b=4)
977 = 33101 (s=8) → 33121 (s=10) → 33203 (s=11) → 33232 (s=13) → 33323 (s=14) → 100021 (s=4) (c=5) (b=4)

1 → 2 → 4 → 13 (s=4) (c=3) (b=5)
105 = 410 (s=5) → 420 (s=6) → 431 (s=8) → 444 (s=12) → 1021 (s=4) (c=4) (b=5)

1 → 2 → 4 → 12 (s=3) (c=3) (b=6)
13 = 21 (s=3) → 24 (s=6) → 34 (s=7) → 45 (s=9) → 102 (s=3) (c=4) (b=6)
396 = 1500 (s=6) → 1510 (s=7) → 1521 (s=9) → 1534 (s=13) → 1555 (s=16) → 2023 (s=7) (c=5) (b=6)

1 → 2 → 4 → 11 (s=2) (c=3) (b=7)
121 = 232 (s=7) → 242 (s=8) → 253 (s=10) → 266 (s=14) → 316 (s=10) (c=4) (b=7)
205 = 412 (s=7) → 422 (s=8) → 433 (s=10) → 446 (s=14) → 466 (s=16) → 521 (s=8) (c=5) (b=7)

1 → 2 → 4 → 10 (s=1) (c=3) (b=8)
8 = 10 (s=1) → 11 (s=2) → 13 (s=4) → 17 (s=8) → 27 (s=9) → 40 (s=4) (c=5) (b=8)
323 = 503 (s=8) → 513 (s=9) → 524 (s=11) → 537 (s=15) → 556 (s=16) → 576 (s=18) → 620 (s=8) (c=6) (b=8)

1 → 2 → 4 → 8 → 17 (s=8) (c=4) (b=9)
6481 = 8801 (s=17) → 8820 (s=18) → 8840 (s=20) → 8862 (s=24) → 8888 (s=32) → 10034 (s=8) (c=5) (b=9)

1 → 2 → 4 → 8 → 16 (s=7) (c=4) (b=10)
50 (s=5) → 55 (s=10) → 65 (s=11) → 76 (s=13) → 89 (s=17) → 106 (s=7) (c=5) (b=10)

1 → 2 → 4 → 8 → 15 (s=6) (c=4) (b=11)
1013 = 841 (s=13) → 853 (s=16) → 868 (s=22) → 888 (s=24) → 8[10][10] (s=28) → 925 (s=16) (c=5) (b=11)

1 → 2 → 4 → 8 → 14 (s=5) (c=4) (b=12)
25 = 21 (s=3) → 24 (s=6) → 2[10] (s=12) → 3[10] (s=13) → 4[11] (s=15) → 62 (s=8) (c=5) (b=12)
1191 = 833 (s=14) → 845 (s=17) → 85[10] (s=23) → 879 (s=24) → 899 (s=26) → 8[11][11] (s=30) → 925 (s=16) (c=6) (b=12)

1 → 2 → 4 → 8 → 13 (s=4) (c=4) (b=13)
781 = 481 (s=13) → 491 (s=14) → 4[10]2 (s=16) → 4[11]5 (s=20) → 4[12][12] (s=28) → 521 (s=8) (c=5) (b=13)
19621 = 8[12]14 (s=25) → 8[12]33 (s=26) → 8[12]53 (s=28) → 8[12]75 (s=32) → 8[12]9[11] (s=40) → 8[12][12][12] (s=44) → 9034 (s=16) (c=6) (b=13)

1 → 2 → 4 → 8 → 12 (s=3) (c=4) (b=14)
72 = 52 (s=7) → 59 (s=14) → 69 (s=15) → 7[10] (s=17) → 8[13] (s=21) → [10]6 (s=16) (c=5) (b=14)
1275 = 671 (s=14) → 681 (s=15) → 692 (s=17) → 6[10]5 (s=21) → 6[11][12] (s=29) → 6[13][13] (s=32) → 723 (s=12) (c=6) (b=14)
19026 = 6[13]10 (s=20) → 6[13]26 (s=27) → 6[13]45 (s=28) → 6[13]65 (s=30) → 6[13]87 (s=34) → 6[13][10][13] (s=42) → 6[13][13][13] (s=45) → 7032 (s=12) (c=7) (b=14)

1 → 2 → 4 → 8 → 11 (s=2) (c=4) (b=15)
603 = 2[10]3 (s=15) → 2[11]3 (s=16) → 2[12]4 (s=18) → 2[13]7 (s=22) → 2[14][14] (s=30) → 31[14] (s=18) (c=5) (b=15)
1023 = 483 (s=15) → 493 (s=16) → 4[10]4 (s=18) → 4[11]7 (s=22) → 4[12][14] (s=30) → 4[14][14] (s=32) → 521 (s=8) (c=6) (b=15)
1891 = 861 (s=15) → 871 (s=16) → 882 (s=18) → 895 (s=22) → 8[10][12] (s=30) → 8[12][12] (s=32) → 8[14][14] (s=36) → 925 (s=16) (c=7) (b=15)

1 → 2 → 4 → 8 → 10 (s=1) (c=4) (b=16)
16 = 10 (s=1) → 11 (s=2) → 13 (s=4) → 17 (s=8) → 1[15] (s=16) → 2[15] (s=17) → 40 (s=4) (c=6) (b=16)
1396 = 574 (s=16) → 584 (s=17) → 595 (s=19) → 5[10]8 (s=23) → 5[11][15] (s=31) → 5[13][14] (s=32) → 5[15][14] (s=34) → 620 (s=8) (c=7) (b=16)
2131 = 853 (s=16) → 863 (s=17) → 874 (s=19) → 887 (s=23) → 89[14] (s=31) → 8[11][13] (s=32) → 8[13][13] (s=34) → 8[15][15] (s=38) → 925 (s=16) (c=8) (b=16)

1 → 2 → 4 → 8 → [16] (s=16) → 1[15] (s=16) (c=5) (b=17)

1 → 2 → 4 → 8 → [16] (s=16) → 1[14] (s=15) (c=5) (b=18)
5330 = [16]82 (s=26) → [16]9[10] (s=35) → [16][11]9 (s=36) → [16][13]9 (s=38) → [16][15][11] (s=42) → [16][17][17] (s=50) → [17]2[13] (s=32) (c=6) (b=18)

1 → 2 → 4 → 8 → [16] (s=16) → 1[13] (s=14) (c=5) (b=19)
116339 = [16][18]52 (s=41) → [16][18]75 (s=46) → [16][18]9[13] (s=56) → [16][18][12][12] (s=58) → [16][18][15][13] (s=62) → [16][18][18][18] (s=70) → [17]03[12] (s=32) (c=6) (b=19)

1 → 2 → 4 → 8 → [16] (s=16) → 1[12] (s=13) (c=5) (b=20)
100 = 50 (s=5) → 55 (s=10) → 5[15] (s=20) → 6[15] (s=21) → 7[16] (s=23) → 8[19] (s=27) → [10]6 (s=16) (c=6) (b=20)
135665 = [16][19]35 (s=43) → [16][19]58 (s=48) → [16][19]7[16] (s=58) → [16][19][10][14] (s=59) → [16][19][13][13] (s=61) → [16][19][16][14] (s=65) → [16][19][19][19] (s=73) → [17]03[12] (s=32) (c=7) (b=20)

N-route

In maths, one thing leads to another. I wondered whether, in a spiral of integers, any number was equal to the digit-sum of the numbers on the route traced by moving to the origin first horizontally, then vertically. To illustrate the procedure, here is a 9×9 integer spiral containing 81 numbers:

| 65 | 64 | 63 | 62 | 61 | 60 | 59 | 58 | 57 |
| 66 | 37 | 36 | 35 | 34 | 33 | 32 | 31 | 56 |
| 67 | 38 | 17 | 16 | 15 | 14 | 13 | 30 | 55 |
| 68 | 39 | 18 | 05 | 04 | 03 | 12 | 29 | 54 |
| 69 | 40 | 19 | 06 | 01 | 02 | 11 | 28 | 53 |
| 70 | 41 | 20 | 07 | 08 | 09 | 10 | 27 | 52 |
| 71 | 42 | 21 | 22 | 23 | 24 | 25 | 26 | 51 |
| 72 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
| 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 |

Take the number 21, which is three places across and up from the bottom left corner of the spiral. The route to the origin contains the numbers 21, 22, 23, 8 and 1, because first you move right two places, then up two places. And 21 is what I call a route number, because 21 = 3 + 4 + 5 + 8 + 1 = digitsum(21) + digitsum(22) + digitsum(23) + digitsum(8) + digitsum(1). Beside the trivial case of 1, there are two more route numbers in the spiral:

58 = 13 + 14 + 6 + 7 + 7 + 6 + 4 + 1 = digitsum(58) + digitsum(59) + digitsum(60) + digitsum(61) + digitsum(34) + digitsum(15) + digitsum(4) + digitsum(1).

74 = 11 + 12 + 13 + 14 + 10 + 5 + 8 + 1 = digitsum(74) + digitsum(75) + digitsum(76) + digitsum(77) + digitsum(46) + digitsum(23) + digitsum(8) + digitsum(1).

Then I wondered about other possible routes to the origin. Think of the origin as one corner of a rectangle and the number being tested as the diagonal corner. Suppose that you always move away from the starting corner, that is, you always move up or right (or up and left, and so on, depending on where the corners lie). In a x by y rectangle, how many routes are there between the diagonal corners under those conditions?

It’s an interesting question, but first I’ve looked at the simpler case of an n by n square. You can encode each route as a binary number, with 0 representing a vertical move and 1 representing a horizontal move. The problem then becomes equivalent to finding the number of distinct ways you can arrange equal numbers of 1s and 0s. If you use this method, you’ll discover that there are two routes across the 2×2 square, corresponding to the binary numbers 01 and 10:

2x2

Across the 3×3 square, there are six routes, corresponding to the binary numbers 0011, 0101, 0110, 1001, 1010 and 1100:

3x3

Across the 4×4 square, there are twenty routes:
4x4

(Please open in new window if it fails to animate)

(Please open in new window if it fails to animate)

Across the 5×5 square, there are 70 routes:

5x5

(Please open in new window etc)

(Please open in new window etc)

Across the 6×6 and 7×7 squares, there are 252 and 924 routes:

6x6

7x7

After that, the routes quickly increase in number. This is the list for n = 1 to 14:

1, 2, 6, 20, 70, 252, 924, 3432, 12870, 48620, 184756, 705432, 2704156, 10400600… (see A000984 at the Online Encyclopedia of Integer Sequences)

After that you can vary the conditions. What if you can move not just vertically and horizontally, but diagonally, i.e. vertically and horizontally at the same time? Now you can encode the route with a ternary number, or number in base 3, with 0 representing a vertical move, 1 a horizontal move and 2 a diagonal move. As before, there is one route across a 1×1 square, but there are three across a 2×2, corresponding to the ternary numbers 01, 2 and 10:

3x3t

There are 13 routes across a 3×3 square, corresponding to the ternary numbers 0011, 201, 021, 22, 0101, 210, 1001, 120, 012, 102, 0110, 1010, 1100:

4x4t

And what about cubes, hypercubes and higher?

Prime Climb Time

The third prime is equal to the sum of the first and second primes: 2 + 3 = 5. After that, for obvious reasons, the prime-sum climbs much more rapidly than the primes themselves:

2, 3, 05, 07, 11, 13, 17, 19, 023, 029...
2, 5, 10, 17, 28, 41, 58, 77, 100, 129...

But what if you use digit-sum(p1..pn), i.e., the sum of the digits of the primes from the first to the nth? For example, the digit-sum(p1..p5) = 2 + 3 + 5 + 7 + 1+1 = 19, whereas the sum(p1..p5) = 2 + 3 + 5 + 7 + 11 = 28. Using the digit-sums of the primes, the comparison now looks like this:

2, 3, 05, 07, 11, 13, 17, 19, 23, 29...
2, 5, 10, 17, 19, 23, 31, 41, 46, 57...

The sum climbs more slowly, but still too fast. So what about a different base? In base-2, the digit-sum(p1..p3) = (1+0) + (1+1) + (1+0+1) = 1 + 2 + 2 = 5. The comparison looks like this:

2, 3, 05, 07, 11, 13, 17, 19, 23, 29...
1, 3, 05, 08, 11, 14, 16, 19, 23, 27...

For primes 3, 5, 11, 19, and 23, p = digit-sum(primes <= p) in base-2. But the cumulative digit-sum soon begins to climb too slowly:

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271...

1, 3, 5, 8, 11, 14, 16, 19, 23, 27, 32, 35, 38, 42, 47, 51, 56, 61, 64, 68, 71, 76, 80, 84, 87, 091, 096, 101, 106, 110, 117, 120, 123, 127, 131, 136, 141, 145, 150, 155, 160, 165, 172, 175, 179, 184, 189, 196, 201, 206, 211, 218, 223, 230, 232, 236, 240, 245...

So what about base-3?

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59...
2, 3, 6, 9, 12, 15, 20, 23, 28, 31, 34, 37, 42, 47, 52, 59, 64...

In base-3, for p = 2, 3 and 37, p = digit-sum(primes <= p), while for p = 23, 31, 47 and 59, p = digit-sum(primes < p), like this:

2 = 2.
3 = 2 + (1+0).
37 = 2 + (1+0) + (1+2) + (2+1) + (1+0+2) + (1+1+1) + (1+2+2) + (2+0+1) + (2+1+2) + (1+0+0+2) + (1+0+1+1) + (1+1+0+1) = 2 + 1 + 3 + 3 + 3 + 3 + 5 + 3 + 5 + 3 + 3 + 3.

23 = 2 + (1+0) + (1+2) + (2+1) + (1+0+2) + (1+1+1) + (1+2+2) + (2+0+1) = 2 + 1 + 3 + 3 + 3 + 3 + 5 + 3.
31 = 2 + (1+0) + (1+2) + (2+1) + (1+0+2) + (1+1+1) + (1+2+2) + (2+0+1) + (2+1+2) + (1+0+0+2) = 2 + 1 + 3 + 3 + 3 + 3 + 5 + 3 + 5 + 3.
47 = 2 + (1+0) + (1+2) + (2+1) + (1+0+2) + (1+1+1) + (1+2+2) + (2+0+1) + (2+1+2) + (1+0+0+2) + (1+0+1+1) + (1+1+0+1) + (1+1+1+2) + (1+1+2+1) = 2 + 1 + 3 + 3 + 3 + 3 + 5 + 3 + 5 + 3 + 3 + 3 + 5 + 5.
59 = 2 + (1+0) + (1+2) + (2+1) + (1+0+2) + (1+1+1) + (1+2+2) + (2+0+1) + (2+1+2) + (1+0+0+2) + (1+0+1+1) + (1+1+0+1) + (1+1+1+2) + (1+1+2+1) + (1+2+0+2) + (1+2+2+2) = 2 + 1 + 3 + 3 + 3 + 3 + 5 + 3 + 5 + 3 + 3 + 3 + 5 + 5 + 5 + 7.

This carries on for a long time. For these primes, p = digit-sum(primes < p):

23, 31, 47, 59, 695689, 698471, 883517, 992609, 992737, 993037, 1314239, 1324361, 1324571, 1326511, 1327289, 1766291, 3174029

And for these primes, p = digit-sum(primes <= p):

3, 37, 695663, 695881, 1308731, 1308757, 1313153, 1314301, 1326097, 1766227, 3204779, 14328191

Now try the cumulative digit-sum in base-4:

2, 3, 5, 07, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59...
2, 5, 7, 11, 16, 20, 22, 26, 31, 36, 43, 47, 52, 59, 67, 72, 80... 

The sum of digits climbs too fast. Base-3 is the Goldilocks base, climbing neither too slowly, like base-2, nor too fast, like all bases greater than 3.