The Viscount of Bi-Count

Today is 22/2/22 and, as I hoped on 2/2/22, I can say more about an interesting little palindromic-pattern problem. For each set of integers <= 1[0]1 in base 10, I looked at the count of palindromes exactly divisible by 1, 2, 3, 4, 5, 6, 7, 8 and 9. For example, 2, 4, 6 and 8 are the 4 palindromes divisible by 2 that are less than 11, so countdiv(2) = 4 for pal <= 11; 3, 6 and 9 are the 3 palindromes divisible by 3, so countdiv(3) = 3; and so on. Here are the counts — and some interesting patterns — for palindromes <= (powers-of-10 + 1) up to 1,000,000,000,001:

count for palindromes <= 101 (prime)

countdiv(1) = 19
countdiv(2) = 8
countdiv(3) = 6
countdiv(4) = 4
countdiv(5) = 2
countdiv(6) = 2
countdiv(7) = 2
countdiv(8) = 2
countdiv(9) = 2


count for palindromes <= 1001 = 7 * 11 * 13

countdiv(1) = 109
countdiv(2) = 48
countdiv(3) = 36
countdiv(4) = 24
countdiv(5) = 12
countdiv(6) = 15
countdiv(7) = 15
countdiv(8) = 12
countdiv(9) = 12


count for palindromes <= 10001 = 73 * 137

countdiv(1) = 199
countdiv(2) = 88
countdiv(3) = 66
countdiv(4) = 44
countdiv(5) = 22
countdiv(6) = 28
countdiv(7) = 32
countdiv(8) = 22
countdiv(9) = 22


count for palindromes <= 100001 = 11 * 9091

countdiv(1) = 1099
countdiv(2) = 488
countdiv(3) = 366
countdiv(4) = 244
countdiv(5) = 122
countdiv(6) = 161
countdiv(7) = 163
countdiv(8) = 122
countdiv(9) = 122


count for palindromes <= 1000001 = 101 * 9901

countdiv(1) = 1999
countdiv(2) = 888
countdiv(3) = 666
countdiv(4) = 444
countdiv(5) = 222
countdiv(6) = 294
countdiv(7) = 303
countdiv(8) = 222
countdiv(9) = 222


count for palindromes <= 10000001 = 11 * 909091

countdiv(1) = 10999
countdiv(2) = 4888
countdiv(3) = 3666
countdiv(4) = 2444
countdiv(5) = 1222
countdiv(6) = 1627
countdiv(7) = 1588
countdiv(8) = 1222
countdiv(9) = 1222


count for palindromes <= 100000001 = 17 * 5882353

countdiv(1) = 19999
countdiv(2) = 8888
countdiv(3) = 6666
countdiv(4) = 4444
countdiv(5) = 2222
countdiv(6) = 2960
countdiv(7) = 2878
countdiv(8) = 2222
countdiv(9) = 2222


count for palindromes <= 1000000001 = 7 * 11 * 13 * 19 * 52579

countdiv(1) = 109999
countdiv(2) = 48888
countdiv(3) = 36666
countdiv(4) = 24444
countdiv(5) = 12222
countdiv(6) = 16293
countdiv(7) = 15734
countdiv(8) = 12222
countdiv(9) = 12222


count for palindromes <= 10000000001 = 101 * 3541 * 27961

countdiv(1) = 199999
countdiv(2) = 88888
countdiv(3) = 66666
countdiv(4) = 44444
countdiv(5) = 22222
countdiv(6) = 29626
countdiv(7) = 28783
countdiv(8) = 22222
countdiv(9) = 22222


count for palindromes <= 100000000001 = 11^2 * 23 * 4093 * 8779

countdiv(1) = 1099999
countdiv(2) = 488888
countdiv(3) = 366666
countdiv(4) = 244444
countdiv(5) = 122222
countdiv(6) = 162959
countdiv(7) = 157361
countdiv(8) = 122222
countdiv(9) = 122222


count for palindromes <= 1000000000001 = 73 * 137 * 99990001

countdiv(1) = 1999999
countdiv(2) = 888888
countdiv(3) = 666666
countdiv(4) = 444444
countdiv(5) = 222222
countdiv(6) = 296292
countdiv(7) = 286461
countdiv(8) = 222222
countdiv(9) = 222222


As you can see, the counts for some numbers alternate between rep-digits (all digits the same) and nearly rep-digits. For example, the counts for palindromes exactly divisible by 5, 8 and 9 are alternately all 2s or 1 followed by all 2s. And you get counts of 2, 12, 22, 122, 222, 1222, 2222 in other even bases greater than base 2 when the counts are represented in that base. Here’s base 8:

count for palindromes <= 101 in b8 = 65 in b10 = 5 * 13

countdiv(1) = 17 in b8 (15 in b10)
countdiv(2) = 6
countdiv(3) = 11 in b8 (9)
countdiv(4) = 2
countdiv(5) = 3
countdiv(6) = 4
countdiv(7) = 2


count for palindromes <= 1001 in b8 = 513 in b10 = 3^3 * 19

countdiv(1) = 107 in b8 (71 in b10)
countdiv(2) = 36 in b8 (30)
countdiv(3) = 34 in b8 (28)
countdiv(4) = 12 in b8 (10)
countdiv(5) = 20 in b8 (16)
countdiv(6) = 14 in b8 (12)
countdiv(7) = 12 in b8 (10)


count for palindromes <= 10001 in b8 = 4097 in b10 = 17 * 241

countdiv(1) = 177 in b8 (127 in b10)
countdiv(2) = 66 in b8 (54)
countdiv(3) = 123 in b8 (83)
countdiv(4) = 22 in b8 (18)
countdiv(5) = 34 in b8 (28)
countdiv(6) = 44 in b8 (36)
countdiv(7) = 22 in b8 (18)


count for palindromes <= 100001 in b8 = 32769 in b10 = 3^2 * 11 * 331

countdiv(1) = 1077 in b8 (575 in b10)
countdiv(2) = 366 in b8 (246)
countdiv(3) = 352 in b8 (234)
countdiv(4) = 122 in b8 (82)
countdiv(5) = 164 in b8 (116)
countdiv(6) = 144 in b8 (100)
countdiv(7) = 122 in b8 (82)


count for palindromes <= 1000001 in b8 = 262145 in b10 = 5 * 13 * 37 * 109

countdiv(1) = 1777 in b8 (1023 in b10)
countdiv(2) = 666 in b8 (438)
countdiv(3) = 1251 in b8 (681)
countdiv(4) = 222 in b8 (146)
countdiv(5) = 316 in b8 (206)
countdiv(6) = 444 in b8 (292)
countdiv(7) = 222 in b8 (146)


count for palindromes <= 10000001 in b8 = 2097153 in b10 = 3^2 * 43 * 5419

countdiv(1) = 10777 in b8 (4607 in b10)
countdiv(2) = 3666 in b8 (1974)
countdiv(3) = 3524 in b8 (1876)
countdiv(4) = 1222 in b8 (658)
countdiv(5) = 1645 in b8 (933)
countdiv(6) = 1444 in b8 (804)
countdiv(7) = 1222 in b8 (658)


count for palindromes <= 100000001 in b8 = 16777217 in b10 = 97 * 257 * 673

countdiv(1) = 17777 in b8 (8191 in b10)
countdiv(2) = 6666 in b8 (3510)
countdiv(3) = 12523 in b8 (5459)
countdiv(4) = 2222 in b8 (1170)
countdiv(5) = 3164 in b8 (1652)
countdiv(6) = 4444 in b8 (2340)
countdiv(7) = 2222 in b8 (1170)


The counts for 4-palindromes and 7-palindromes in base 8 run: 1, 12, 22, 122, 222, 1222, 2222…, just like the counts for 5-palindromes, 8-palindromes and 9-palindromes in base 10. Here’s base 14:

count for palindromes <= 101 in b14 = 197 in b10 (prime)

countdiv(1) = 1D in b14 (27 in b10)
countdiv(2) = C in b14 (12)
countdiv(3) = 13 in b14 (17)
countdiv(4) = 6
countdiv(5) = 11 in b14 (15)
countdiv(6) = 8
countdiv(7) = 2
countdiv(8) = 2
countdiv(9) = 5
countdiv(A) = 7
countdiv(B) = 2
countdiv(C) = 4
countdiv(D) = 2


count for palindromes <= 1001 in b14 = 2745 in b10 = 3^2 * 5 * 61

countdiv(1) = 10D in b14 (209 in b10)
countdiv(2) = 6C in b14 (96)
countdiv(3) = 58 in b14 (78)
countdiv(4) = 36 in b14 (48)
countdiv(5) = 3A in b14 (52)
countdiv(6) = 28 in b14 (36)
countdiv(7) = 12 in b14 (16)
countdiv(8) = 19 in b14 (23)
countdiv(9) = 1C in b14 (26)
countdiv(A) = 19 in b14 (23)
countdiv(B) = 14 in b14 (18)
countdiv(C) = 14 in b14 (18)
countdiv(D) = 12 in b14 (16)


count for palindromes <= 10001 in b14 = 38417 in b10 = 41 * 937

countdiv(1) = 1DD in b14 (391 in b10)
countdiv(2) = CC in b14 (180)
countdiv(3) = 147 in b14 (259)
countdiv(4) = 66 in b14 (90)
countdiv(5) = 129 in b14 (233)
countdiv(6) = 88 in b14 (120)
countdiv(7) = 22 in b14 (30)
countdiv(8) = 31 in b14 (43)
countdiv(9) = 66 in b14 (90)
countdiv(A) = 79 in b14 (107)
countdiv(B) = 26 in b14 (34)
countdiv(C) = 44 in b14 (60)
countdiv(D) = 22 in b14 (30)


count for palindromes <= 100001 in b14 = 537825 in b10 = 3 * 5^2 * 71 * 101

countdiv(1) = 10DD in b14 (2939 in b10)
countdiv(2) = 6CC in b14 (1356)
countdiv(3) = 594 in b14 (1110)
countdiv(4) = 366 in b14 (678)
countdiv(5) = 3B2 in b14 (744)
countdiv(6) = 288 in b14 (512)
countdiv(7) = 122 in b14 (226)
countdiv(8) = 1A1 in b14 (337)
countdiv(9) = 1CA in b14 (374)
countdiv(A) = 1A7 in b14 (343)
countdiv(B) = 150 in b14 (266)
countdiv(C) = 144 in b14 (256)
countdiv(D) = 122 in b14 (226)


count for palindromes <= 1000001 in b14 = 7529537 in b10 = 37 * 197 * 1033

countdiv(1) = 1DDD in b14 (5487 in b10)
countdiv(2) = CCC in b14 (2532)
countdiv(3) = 1493 in b14 (3657)
countdiv(4) = 666 in b14 (1266)
countdiv(5) = 12B1 in b14 (3291)
countdiv(6) = 888 in b14 (1688)
countdiv(7) = 222 in b14 (422)
countdiv(8) = 331 in b14 (631)
countdiv(9) = 63A in b14 (1228)
countdiv(A) = 7A7 in b14 (1519)
countdiv(B) = 278 in b14 (498)
countdiv(C) = 444 in b14 (844)
countdiv(D) = 222 in b14 (422)


count for palindromes <= 10000001 in b14 = 105413505 in b10 = 3 * 5 * 7027567

countdiv(1) = 10DDD in b14 (41159 in b10)
countdiv(2) = 6CCC in b14 (18996)
countdiv(3) = 5948 in b14 (15548)
countdiv(4) = 3666 in b14 (9498)
countdiv(5) = 3B2A in b14 (10426)
countdiv(6) = 2888 in b14 (7176)
countdiv(7) = 1222 in b14 (3166)
countdiv(8) = 1A31 in b14 (4747)
countdiv(9) = 1C6D in b14 (5193)
countdiv(A) = 1A79 in b14 (4811)
countdiv(B) = 1513 in b14 (3741)
countdiv(C) = 1444 in b14 (3588)
countdiv(D) = 1222 in b14 (3166)


count for palindromes <= 100000001 in b14 = 1475789057 in b10 = 17 * 5393 * 16097

countdiv(1) = 1DDDD in b14 (76831 in b10)
countdiv(2) = CCCC in b14 (35460)
countdiv(3) = 14947 in b14 (51219)
countdiv(4) = 6666 in b14 (17730)
countdiv(5) = 12B29 in b14 (46097)
countdiv(6) = 8888 in b14 (23640)
countdiv(7) = 2222 in b14 (5910)
countdiv(8) = 3331 in b14 (8863)
countdiv(9) = 631D in b14 (17079)
countdiv(A) = 7A79 in b14 (21275)
countdiv(B) = 278B in b14 (6983)
countdiv(C) = 4444 in b14 (11820)
countdiv(D) = 2222 in b14 (5910)


Now 7-palindromes and D-palindromes (D = 13 in base 10) are following the [1]2222… pattern. What explains it? If you’re good at math, you won’t need telling. But I’m not good at maths, so I’m going to tell myself and other members of the not-good-at-math community what’s going on. Let’s go back to base 10 and the counts for 5-palindromes, that is, palindromes exactly divisible by 5. In base 10, the only integers exactly divisible by 5 have to end in either 5 or 0. But a palindrome can’t end in 0, because then the leading digit would have to be 0 too. Therefore only palindromes ending in 5 are exactly divisible by 5 in base 10. And if the palindromes end in 5, they have to start with 5 too.

Once we know that, we can easily calculate, for a given number of digits, how many 5-palindromes there are. Take 5-palindromes with three digits. If the three-digit 5-palindromes end and start with 5, we have to consider only the middle digit, which can obviously range from 0 to 9: 505, 515, 525, 535, 545, 555, 565, 575, 585 and 595. So there are 10 3-digit 5-palindromes. We add that count to the count for the single one-digit 5-palindrome, 5, and the single two-digit 5-palindrome, 55. So the cumulative count for 5-palindromes < 1001 is: 10 + 1 + 1 = 12.

Now look at four-digit 5-palindromes. They start and end with 5, therefore we have to consider only the middle two digits. And those middle digits have to be identical: 5005, 5115, 5225, 5335, 5445, 5555, 5665, 5775, 5885, 5995. So there are also 10 four-digit 5-palindromes and count of 5-palindromes < 10001 is: 10 + 10 + 1 + 1 = 22.

Now look at five-digit 5-palindromes. Again we have consider only the middle digits, because the first and fifth digits have to be 5. The second digit of a five-digit 5-palindrome has to be the same as the fourth digit: 50005, 51715, 52425, 53135, and so on. And the second and fourth digits can obviously range from 0 to 9. And so can the third and middle digit of the 5-palindromes. But the third digit doesn’t have to be the same as the second and fourth digits: 50005, 50105, 50205, and so on. Therefore the number of five-digit 5-palindromes is 10 * 10 = 100. And the count of 5-palindromes < 100001 is: 100 + 10 + 10 + 1 + 1 = 122.

Now look at six-digit 5-palindromes. The second digit of a six-digit 5-palindrome has to be same as the fifth digit and the third digit has to be the same as the fourth digit. So once you have the second and third digits, you automatically have the fourth and fifth digits: 500005, 523325, 587785, and so on. Clearly, the second and third digits range from 00 to 99 (i.e., 00, 01, 02 … 97, 98, 99), so there must be 100 six-digit 6-palindromes. And the count of 5-palindromes < 1000001 is: 100 + 100 + 10 + 10 + 1 + 1 = 222.

It should be clear, then, that the count of 5-palindromes for an odd number of digits, d, will be always the same as the count of 5-palindromes for the even number of digits d+1. There is 1 one-digit 5-palindrome, namely 5, and 1 two-digit 5-palindrome, namely 55. There are 10 three-digit 5-palindromes, 505 to 595, and 10 four-digit 5-palindromes, 5005 to 5995. Now, the count of 5-palindromes with an odd number of digits, d, will be equal to 10^(d\2), where d\2 = (d-1)/2. And the count for 5-palindromes with the even number of digits d+1 will be the same, 10^(d\2). Therefore the count for both sets of 5-palindromes, d-digit palindromes and (d+1)-digit palindromes, will be 2 * 10^(d\2). And that’s why the cumulative count of 5-palindromes looks the way it does in base 10: 1, 2, 12, 22, 122, 222, 1222, 2222, 12222, 22222…

The same reasoning applies in other even bases greater than base 2. When a palindrome divisible by a particular number has to start and end with the same digit, s, in base b, the middle digits will dictate a count of b^(d\2) for both d-digit s-palindromes and (d+1)-digit s-palindromes. And you’ll get the same cumulative count for s-palindromes in that base: 1, 2, 12, 22, 122, 222, 1222, 2222, 12222, 22222…

Some other patterns in the palindrome-counts can be explained by extending the reasoning given above. For example, if an s-palindrome can begin and end with two possible numbers, you’ll get cumulative counts of 2, 4, 24, 44, 244, 444, 2444, 4444, 24444, 44444 and so on. If the s-palindrome can end with three possible numbers, you’ll get cumulative counts of 3, 6, 36, 66, 366, 666, 3666, 6666, 36666, 66666 and so on.


Post-Performative Post-Scriptum

The discussion above is of very simple mathematics, but that’s the only kind I can cope with. All the same, I’m pleased that I managed to work out why the count of 5-palindromes behaves like that in base 10. So I’ve decided to award myself a title. Remember that the count for 5-palindromes of length d and d+1 is 2 * 10^(d\2), where d is an odd number. And you could say that 2 * 10^(d\2) is a bi-count of 10^(d\2). So I’m calling myself the Viscount of Bi-Count.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.