# The Devil’s Digits

As I’ve said before, I love the way that numbers can come in many different guises. For example, take the number 21. It comes in all these guises:

21 = 10101 in base 2 = 210 in base 3 = 111 in b4 = 41 in b5 = 33 in b6 = 30 in b7 = 25 in b8 = 23 in b9 = 21 in b10 = 1A in b11 = 19 in b12 = 18 in b13 = 17 in b14 = 16 in b15 = 15 in b16 = 14 in b17 = 13 in b18 = 12 in b19 = 11 in b20 = 10 in b21

But I’ve not chosen 21 at random. If you sum the 1s in the representations of 21 in bases 2 to 21, look what you get:

21 = 10101 in base 2 = 210 in base 3 = 111 in b4 = 41 in b5 = 33 in b6 = 30 in b7 = 25 in b8 = 23 in b9 = 21 in b10 = 1A in b11 = 19 in b12 = 18 in b13 = 17 in b14 = 16 in b15 = 15 in b16 = 14 in b17 = 13 in b18 = 12 in b19 = 11 in b20 = 10 in b21

21 = 1s=101s=201s=3 in base 2 = 21s=40 in base 3 = 111s=7 in b4 = 41s=8 in b5 = 33 in b6 = 30 in b7 = 25 in b8 = 23 in b9 = 21s=9 in b10 = 1s=10A in b11 = 1s=119 in b12 = 1s=128 in b13 = 1s=137 in b14 = 1s=146 in b15 = 1s=155 in b16 = 1s=164 in b17 = 1s=173 in b18 = 1s=182 in b19 = 11s=20 in b20 = 1s=210 in b21

In other words, 21 = digcount(21,dig=1,base=2..21). But n = digcount(n,dig,b=2..n) doesn’t happen for any other digit and doesn’t happen often with 1:

3 = digcount(3,d=1,b=2..3) = 11 in b2 = 10 in b3
4 = digcount(4,d=1,b=2..4) = 100 in b2 = 11 in b3 = 10 in b4
6 = digcount(6,d=1,b=2..6) = 110 in b2 = 20 in b3 = 12 in b4 = 11 in b5 = 10 in b6
10 = digcount(10,d=1) = 1010 in b2 = 101 in b3 = 22 in b4 = 20 in b5 = 14 in b6 = 13 in b7 = 12 in b8 = 11 in b9 = 10 in b10
15 = digcount(15,d=1) = 1111 in b2 = 120 in b3 = 33 in b4 = 30 in b5 = 23 in b6 = 21 in b7 = 17 in b8 = 16 in b9 = 15 in b10 = 14 in b11 = 13 in b12 = 12 in b13 = 11 in b14 = 10 in b15
21 = digcount(21,d=1) = 10101 in b2 = 210 in b3 = 111 in b4 = 41 in b5 = 33 in b6 = 30 in b7 = 25 in b8 = 23 in b9 = 21 in b10 = 1A in b11 = 19 in b12 = 18 in b13 = 17 in b14 = 16 in b15 = 15 in b16 = 14 in b17 = 13 in b18 = 12 in b19 = 11 in b20 = 10 in b21

After that, the digcount(n,d=1,b=2..n) → n/2 (see “Digital Dissection” for further discussion). But I decided to look for the first n where digcount(n,dig,b=2..n) = 666:

digcount(1270,1) = 666
digcount(3770,2) = 666
digcount(7667,3) = 666
digcount(12184,4) = 666
digcount(18845,5) = 666
digcount(25806,6) = 666
digcount(34195,7) = 666
digcount(43352,8) = 666
digcount(54693,9) = 666

It doesn’t stop there, of course. You can carry on for ever, looking for digcount(n,A) = 666, digcount(n,B) = 666, digcount(n,C) = 666, where A = 10, B = 11 and C=12, and so on. But it doesn’t start there, either. What about digcount(n,0) = 666? That isn’t easy to find, because 0 usually occurs far less often than other digits in the representation of n. Here are the integers setting records for digcount(n,0,b=2..n):

2 → digcount(2,0) = 1 ← 2= 10 in base 2
4 → digcount(4,0) = 3; ← 4 = 100 in base 2, 11 in base 3, 10 in base 4
8 → digcount(8,0) = 5 ← 8 = 1000 in base 2, 22 in base 3, 20 in base 4, 13 in base 5, 12 in base 6, 11 in base 7, 10 in base 8
12 → digcount(12,0) = 6
16 → digcount(16,0) = 8
18 → digcount(18,0) = 9
32 → digcount(32,0) = 11
36 → digcount(36,0) = 13
64 → digcount(64,0) = 15
72 → digcount(72,0) = 18
128 → digcount(128,0) = 20
144 → digcount(144,0) = 24
252 → digcount(252,0) = 25
264 → digcount(264,0) = 27
288 → digcount(288,0) = 29
360 → digcount(360,0) = 30
504 → digcount(504,0) = 33
540 → digcount(540,0) = 36
720 → digcount(720,0) = 40
900 → digcount(900,0) = 42
1080 → digcount(1080,0) = 47
1680 → digcount(1680,0) = 48
1800 → digcount(1800,0) = 53
2160 → digcount(2160,0) = 56
2520 → digcount(2520,0) = 61
3600 → digcount(3600,0) = 64
4320 → digcount(4320,0) = 66

So what is the first n for which digcount(n,0) = 666? Watch this space.

# Digital Rodeo

What a difference a digit makes. Suppose you take all representations of n in bases b <= n. When n = 3, the bases are 2 and 3, so 3 = 11 and 10, respectively. Next, count the occurrences of the digit 1:

digitcount(3, digit=1, n=11, 10) = 3

Add this digit-count to 3:

3 + digitcount(3, digit=1, n=11, 10) = 3 + 3 = 6.

Now apply the same procedure to 6. The bases will be 2 to 6:

6 + digitcount(6, digit=1, n=110, 20, 12, 11, 10) = 6 + 6 = 12

The procedure, n = n + digitcount(n,digit=1,base=2..n), continues like this:

12 + digcount(12,dig=1,n=1100, 110, 30, 22, 20, 15, 14, 13, 12, 11, 10) = 12 + 11 = 23
23 + digcount(23,dig=1,n=10111, 212, 113, 43, 35, 32, 27, 25, 23, 21, 1B, 1A, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10) = 23 + 21 = 44
44 + digcount(44,dig=1,n=101100, 1122, 230, 134, 112, 62, 54, 48, 44, 40, 38, 35, 32, 2E, 2C, 2A, 28, 26, 24, 22, 20, 1L, 1K, 1J, 1I, 1H, 1G, 1F, 1E, 1D, 1C, 1B, 1A, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10) = 44 + 31 = 75

And the sequence develops like this:

3, 6, 12, 23, 44, 75, 124, 202, 319, 503, 780, 1196, 1824, 2766, 4191, 6338, 9546, 14383, 21656, 32562, 48930, 73494, 110361, 165714, 248733, 373303, 560214, 840602, 1261237, 1892269, 2838926, 4258966, 6389157, 9584585, 14377879…

Now try the same procedure using the digit 0: n = n + digcount(n,dig=0,base=2..n). The first step is this:

3 + digcount(3,digit=0,n=11, 10) = 3 + 1 = 4

Next come these:

4 + digcount(4,dig=0,n=100, 11, 10) = 4 + 3 = 7
7 + digcount(7,dig=0,n=111, 21, 13, 12, 11, 10) = 7 + 1 = 8
8 + digcount(8,dig=0,n=1000, 22, 20, 13, 12, 11, 10) = 8 + 5 = 13
13 + digcount(13,dig=0,n=1101, 111, 31, 23, 21, 16, 15, 14, 13, 12, 11, 10) = 13 + 2 = 15
15 + digcount(15,dig=0,n=1111, 120, 33, 30, 23, 21, 17, 16, 15, 14, 13, 12, 11, 10) = 15 + 3 = 18
18 + digcount(18,dig=0,n=10010, 200, 102, 33, 30, 24, 22, 20, 18, 17, 16, 15, 14, 13, 12, 11, 10) = 18 + 9 = 27
27 + digcount(27,dig=0,n=11011, 1000, 123, 102, 43, 36, 33, 30, 27, 25, 23, 21, 1D, 1C, 1B, 1A, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10) = 27 + 7 = 34
34 + digcount(34,dig=0,n=100010, 1021, 202, 114, 54, 46, 42, 37, 34, 31, 2A, 28, 26, 24, 22, 20, 1G, 1F, 1E, 1D, 1C, 1B, 1A, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10) = 34 + 8 = 42
42 + digcount(42,dig=0,n=101010, 1120, 222, 132, 110, 60, 52, 46, 42, 39, 36, 33, 30, 2C, 2A, 28, 26, 24, 22, 20, 1K, 1J, 1I, 1H, 1G, 1F, 1E, 1D, 1C, 1B, 1A, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10) = 42 + 9 = 51

The sequence develops like this:

3, 4, 7, 8, 13, 15, 18, 27, 34, 42, 51, 59, 62, 66, 80, 94, 99, 111, 117, 125, 132, 151, 158, 163, 173, 180, 204, 222, 232, 244, 258, 279, 292, 307, 317, 324, 351, 364, 382, 389, 400, 425, 437, 447, 454, 466, 475, 483, 494, 509, 517, 536, 553, 566, 576, 612, 637, 649, 669, 679, 693, 712, 728, 753, 768, 801, 822, 835, 849, 862, 869, 883, 895, 906, 923, 932, 943, 949, 957, 967, 975, 999, 1011…

If you compare it with the sequence for digit=1, it appears that digcount(n,dig=1,b=2..n) is always larger than digcount(n,dig=0,b=2..n). That is in fact the case, with one exception, when n = 2:

digcount(2,dig=1,n=10) = 1
digcount(2,dig=0,n=10) = 1

When n = 10 (in base ten), there are twice as many ones as zeros:

digcount(10,dig=1,n=1010, 101, 22, 20, 14, 13, 12, 11, 10) = 10
digcount(10,dig=0,n=1010, 101, 22, 20, 14, 13, 12, 11, 10) = 5

As n gets larger, the difference grows dramatically:

digcount(100,dig=1,base=2..n) = 64
digcount(100,dig=0,base=2..n) = 16

digcount(1000,dig=1,base=2..n) = 533
digcount(1000,dig=0,base=2..n) = 25

digcount(10000,dig=1,base=2..n) = 5067
digcount(10000,dig=0,base=2..n) = 49

digcount(100000,dig=1,base=2..n) = 50140
digcount(100000,dig=0,base=2..n) = 73

digcount(1000000,dig=1,base=2..n) = 500408
digcount(1000000,dig=0,base=2..n) = 102

digcount(10000000,dig=1,base=2..n) = 5001032
digcount(10000000,dig=0,base=2..n) = 134

digcount(100000000,dig=1,base=2..n) = 50003137
digcount(100000000,dig=0,base=2..n) = 160

In fact, digcount(n,dig=1,b=2..n) is greater than the digit-count for any other digit: 0, 2, 3, 4, 5… (with the exception n = 2, as shown above). But digit=0 sometimes beats digits >= 2. For example, when n = 18:

digcount(18,dig=0,n=10010, 200, 102, 33, 30, 24, 22, 20, 18, 17, 16, 15, 14, 13, 12, 11, 10) = 9
digcount(18,dig=2,n=10010, 200, 102, 33, 30, 24, 22, 20, 18, 17, 16, 15, 14, 13, 12, 11, 10) = 7
digcount(18,dig=3,n=10010, 200, 102, 33, 30, 24, 22, 20, 18, 17, 16, 15, 14, 13, 12, 11, 10) = 4
digcount(18,dig=4,n=10010, 200, 102, 33, 30, 24, 22, 20, 18, 17, 16, 15, 14, 13, 12, 11, 10) = 2
digcount(18,dig=5,n=10010, 200, 102, 33, 30, 24, 22, 20, 18, 17, 16, 15, 14, 13, 12, 11, 10) = 1

But as n gets larger, digcount(0) will fall permanently behind all these digits. However, digcount(0) will always be greater than some digit d, for the obvious reason that some digits only appear when the base is high enough. For example, the hexadecimal digit A (with the decimal value 10) first appears when n = 21:

digcount(21,dig=A,n=10101, 210, 111, 41, 33, 30, 25, 23, 21, 1A, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10) = 1 digcount(21,dig=0,n=10101, 210, 111, 41, 33, 30, 25, 23, 21, 1A, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10) = 5

There is a general rule for the n at which digit d first appears, n = 2d + 1 (this doesn’t apply when d = 0 or d = 1):

d = 2, n = 5 = 2*2 + 1
digcount(5,dig=2,n=101, 12, 11, 10) = 1

d = 3, n = 7 = 2*3 + 1
digcount(7,dig=3,n=111, 21, 13, 12, 11, 10) = 1

d = 4, n = 9 = 2*4 + 1
digcount(9,dig=4,n=1001, 100, 21, 14, 13, 12, 11, 10) = 1

d = 5, n = 11 = 2*5 + 1
digcount(11,dig=5,n=1011, 102, 23, 21, 15, 14, 13, 12, 11, 10) = 1

It should be apparent, then, that the digit-count for a particular digit starts at 1 and gets gradually higher. The rate at which the digit-count increases is highest for 1 and lowest for 0, with digits 2, 3, 4, 5… in between:

Graph for digcount(n,dig=d,b=2..n)

You could think of the graph as a digital rodeo in which these digits compete with each other. 1 is the clear and permanent winner, 0 the gradual loser. Now recall the procedure introduced at the start: n = n + digcount(n,dig=d,b=2..n). When it’s applied to the digits 0 to 5, these are the sequences that appear:

n = n + digcount(n,dig=0,b=2..n)

2, 3, 4, 7, 8, 13, 15, 18, 27, 34, 42, 51, 59, 62, 66, 80, 94, 99, 111, 117, 125, 132, 151, 158, 163, 173, 180, 204, 222, 232, 244, 258, 279, 292, 307, 317, 324, 351, 364, 382, 389, 400, 425, 437, 447, 454, 466, 475, 483, 494, 509, 517, 536, 553, 566, 576, 612, 637, 649, 669, 679, 693, 712, 728, 753, 768, 801, 822, 835, 849, 862, 869, 883, 895, 906, 923, 932, 943, 949, 957, 967, 975, 999, 1011…

n = n + digcount(n,dig=1,b=2..n)

2, 3, 6, 12, 23, 44, 75, 124, 202, 319, 503, 780, 1196, 1824, 2766, 4191, 6338, 9546, 14383, 21656, 32562, 48930, 73494, 110361, 165714, 248733, 373303, 560214, 840602, 1261237, 1892269, 2838926, 4258966, 6389157, 9584585, 14377879…

n = n + digcount(n,dig=2,b=2..n)

5, 6, 8, 12, 16, 22, 31, 37, 48, 60, 76, 94, 115, 138, 173, 213, 257, 311, 374, 454, 542, 664, 790, 935, 1109, 1310, 1552, 1835, 2167, 2548, 2989, 3509, 4120, 4832, 5690, 6687, 7829, 9166, 10727, 12568, 14697, 17182, 20089, 23470, 27425, 32042, 37477, 43768, 51113, 59687, 69705, 81379, 94998, 110910, 129488, 151153, 176429, 205923, 240331, 280490, 327396, 382067, 445858…

n = n + digcount(n,dig=3,b=2..n)

7, 8, 9, 10, 11, 13, 16, 18, 22, 25, 29, 34, 38, 44, 50, 56, 63, 80, 90, 104, 113, 131, 151, 169, 188, 210, 236, 261, 289, 320, 350, 385, 424, 463, 520, 572, 626, 684, 747, 828, 917, 999, 1101, 1210, 1325, 1446, 1577, 1716, 1871, 2040, 2228, 2429, 2642, 2875, 3133, 3413, 3719, 4044, 4402, 4786, 5196, 5645, 6140, 6673, 7257, 7900, 8582, 9315, 10130, 10998, 11942, 12954, 14058…

n = n + digcount(n,dig=4,b=2..n)

9, 10, 11, 12, 13, 14, 16, 18, 20, 23, 25, 28, 34, 41, 44, 52, 61, 67, 74, 85, 92, 102, 113, 121, 134, 148, 170, 184, 208, 229, 253, 269, 287, 306, 324, 356, 386, 410, 439, 469, 501, 531, 565, 604, 662, 703, 742, 794, 845, 895, 953, 1007, 1062, 1127, 1188, 1262, 1336, 1421, 1503, 1585, 1676, 1777, 1876, 2001, 2104, 2249, 2375, 2502, 2636, 2789, 2938, 3102, 3267, 3444, 3644, 3868, 4099…

n = n + digcount(n,dig=5,b=2..n)

11, 12, 13, 14, 15, 16, 17, 19, 21, 23, 26, 28, 29, 33, 37, 41, 48, 50, 55, 60, 64, 67, 72, 75, 83, 91, 96, 102, 107, 118, 123, 129, 137, 151, 159, 171, 180, 192, 202, 211, 224, 233, 251, 268, 280, 296, 310, 324, 338, 355, 380, 401, 430, 455, 488, 511, 536, 562, 584, 607, 638, 664, 692, 718, 748, 778, 807, 838, 874, 911, 951, 993, 1039, 1081, 1124, 1166, 1216, 1264, 1313, 1370, 1432…