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

Advertisements

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

Can You Dij It? #2

It’s very simple, but I’m fascinated by it. I’m talking about something I call the digit-line, or the stream of digits you get when you split numbers in a particular base into individual digits. For example, here are the numbers one to ten in bases 2 and 3:

Base = 2: 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010…
Base = 3: 1, 2, 10, 11, 12, 20, 21, 22, 100, 101…


If you turn them into digit-lines, they look like this:

Base = 2: 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0… (A030190 in the Online Encyclopedia of Integer Sequences)
Base = 3: 1, 2, 1, 0, 1, 1, 1, 2, 2, 0, 2, 1, 2, 2, 1, 0, 0, 1, 0, 1… (A003137 in the OEIS)


At the tenth digit of the two digit-lines, both digits equal zero for the first time:

Base = 2: 1, 1, 0, 1, 1, 1, 0, 0, 1, 0
Base = 3: 1, 2, 1, 0, 1, 1, 1, 2, 2, 0


When the binary and ternary digits are represented together, the digit-lines look like this:

(1,1), (1,2), (0,1), (1,0), (1,1), (1,1), (0,1), (0,2), (1,2), (0,0)


But in base 4, the tenth digit of the digit-line is 1. So when do all the digits of the digit-line first equal zero for bases 2 to 4? Here the early integers in those bases:

Base 2: 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 10000, 10001, 10010, 10011, 10100, 10101…

Base 3: 1, 2, 10, 11, 12, 20, 21, 22, 100, 101, 102, 110, 111, 112, 120, 121, 122, 200, 201, 202, 210, 211, 212, 220, 221, 222, 1000, 1001, 1002…

Base 4: 1, 2, 3, 10, 11, 12, 13, 20, 21, 22, 23, 30, 31, 32, 33, 100, 101, 102, 103, 110, 111, 112, 113, 120, 121, 122, 123, 130, 131, 132, 133, 200…


And here are the digits of the digit-line in bases 2 to 4 represented together:

(1,1,1), (1,2,2), (0,1,3), (1,0,1), (1,1,0), (1,1,1), (0,1,1), (0,2,1), (1,2,2), (0,0,1), (1,2,3), (1,1,2), (1,2,0), (0,2,2), (1,1,1), (1,0,2), (1,0,2), (1,1,2), (0,0,3), (0,1,3), (0,1,0), (1,0,3), (0,2,1), (0,1,3), (1,1,2), (1,0,3), (0,1,3), (1,1,1), (0,1,0), (1,1,0), (0,1,1), (1,2,0), (1,1,1), (1,2,1), (1,0,0), (0,1,2), (0,2,1), (1,1,0), (1,1,3), (0,2,1), (1,2,1), (1,2,0), (1,0,1), (1,0,1), (0,2,1), (1,0,1), (1,1,1), (1,2,2), (1,0,1), (1,2,1), (0,2,3), (0,1,1), (0,0,2), (0,2,0), (1,1,1), (0,1,2), (0,2,1), (0,1,1), (1,2,2), (1,2,2), (0,2,1), (0,0,2), (1,2,3), (0,2,1), (1,1,3), (0,2,0), (0,2,1), (1,2,3), (1,1,1), (1,0,1), (0,0,3), (1,0,2), (0,1,1), (0,0,3), (1,0,3), (0,1,2), (1,1,0), (0,0,0)

At the 78th digit, all three digits equal zero. But the 78th digit of the digit-line in base 5 is 1. So when are the digits first equal to zero in bases 2 to 5? It’s not difficult to find out, but the difficulty of the search increases fast as the bases get bigger. Here are the results up to base 13 (note that bases 11 and 12 both have zeroes at digit 103721663):

dig=0 in bases 2 to 3 at the 10th digit of the digit-line
dig=0 in bases 2 to 4 at the 78th digit of the digit-line
dig=0 in bases 2 to 5 at the 182nd digit of the digit-line
dig=0 in bases 2 to 6 at the 302nd digit of the digit-line
dig=0 in bases 2 to 7 at the 12149th digit of the digit-line
dig=0 in bases 2 to 8 at the 45243rd digit of the digit-line
dig=0 in bases 2 to 9 at the 255261st digit of the digit-line
dig=0 in bases 2 to 10 at the 8850623rd digit of the digit-line
dig=0 in bases 2 to 12 at the 103721663rd digit of the digit-line
dig=0 in bases 2 to 13 at the 807778264th digit of the digit-line


I assume that, for any base b > 2, you can find some point in the digit-line at which d = 0 for all bases 2 to b. Indeed, I assume that this happens infinitely often. But I don’t know any short-cut for finding the first digit at which this occurs.


Previously pre-posted:

Can You Dij It? #1

For Revver and Fevver

This shape reminds me of the feathers on an exotic bird:

feathers

(click or open in new window for full size)


feathers_anim

(animated version)


The shape is created by reversing the digits of a number, so you could say it involves revvers and fevvers. I discovered it when I was looking at the Halton sequence. It’s a sequence of fractions created according to a simple but interesting rule. The rule works like this: take n in base b, reverse it, and divide reverse(n) by the first power of b that is greater thann.

For example, suppose n = 6 and b = 2. In base 2, 6 = 110 and reverse(110) = 011 = 11 = 3. The first power of 2 that is greater than 6 is 2^3 or 8. Therefore, halton(6) in base 2 equals 3/8. Here is the same procedure applied to n = 1..20:

1: halton(1) = 1/10[2] → 1/2
2: halton(10) = 01/100[2] → 1/4
3: halton(11) = 11/100[2] → 3/4
4: halton(100) = 001/1000[2] → 1/8
5: halton(101) = 101/1000[2] → 5/8
6: halton(110) = 011/1000 → 3/8
7: halton(111) = 111/1000 → 7/8
8: halton(1000) = 0001/10000 → 1/16
9: halton(1001) = 1001/10000 → 9/16
10: halton(1010) = 0101/10000 → 5/16
11: halton(1011) = 1101/10000 → 13/16
12: halton(1100) = 0011/10000 → 3/16
13: halton(1101) = 1011/10000 → 11/16
14: halton(1110) = 0111/10000 → 7/16
15: halton(1111) = 1111/10000 → 15/16
16: halton(10000) = 00001/100000 → 1/32
17: halton(10001) = 10001/100000 → 17/32
18: halton(10010) = 01001/100000 → 9/32
19: halton(10011) = 11001/100000 → 25/32
20: halton(10100) = 00101/100000 → 5/32…

Note that the sequence always produces reduced fractions, i.e. fractions in their lowest possible terms. Once 1/2 has appeared, there is no 2/4, 4/8, 8/16…; once 3/4 has appeared, there is no 6/8, 12/16, 24/32…; and so on. If the fractions are represented as points in the interval [0,1], they look like this:

line1_1_2

point = 1/2


line2_1_4

point = 1/4


line3_3_4

point = 3/4


line4_1_8

point = 1/8


line5_5_8

point = 5/8


line6_3_8

point = 3/8


line7_7_8

point = 7/8


line_b2_anim

(animated line for base = 2, n = 1..63)


It’s apparent that Halton points in base 2 will evenly fill the interval [0,1]. Now compare a Halton sequence in base 3:

1: halton(1) = 1/10[3] → 1/3
2: halton(2) = 2/10[3] → 2/3
3: halton(10) = 01/100[3] → 1/9
4: halton(11) = 11/100[3] → 4/9
5: halton(12) = 21/100[3] → 7/9
6: halton(20) = 02/100 → 2/9
7: halton(21) = 12/100 → 5/9
8: halton(22) = 22/100 → 8/9
9: halton(100) = 001/1000 → 1/27
10: halton(101) = 101/1000 → 10/27
11: halton(102) = 201/1000 → 19/27
12: halton(110) = 011/1000 → 4/27
13: halton(111) = 111/1000 → 13/27
14: halton(112) = 211/1000 → 22/27
15: halton(120) = 021/1000 → 7/27
16: halton(121) = 121/1000 → 16/27
17: halton(122) = 221/1000 → 25/27
18: halton(200) = 002/1000 → 2/27
19: halton(201) = 102/1000 → 11/27
20: halton(202) = 202/1000 → 20/27
21: halton(210) = 012/1000 → 5/27
22: halton(211) = 112/1000 → 14/27
23: halton(212) = 212/1000 → 23/27
24: halton(220) = 022/1000 → 8/27
25: halton(221) = 122/1000 → 17/27
26: halton(222) = 222/1000 → 26/27
27: halton(1000) = 0001/10000 → 1/81
28: halton(1001) = 1001/10000 → 28/81
29: halton(1002) = 2001/10000 → 55/81
30: halton(1010) = 0101/10000 → 10/81

And here is an animated gif representing the Halton sequence in base 3 as points in the interval [0,1]:

line_b3_anim


Halton points in base 3 also evenly fill the interval [0,1]. What happens if you apply the Halton sequence to a two-dimensional square rather a one-dimensional line? Suppose the bottom left-hand corner of the square has the co-ordinates (0,0) and the top right-hand corner has the co-ordinates (1,1). Find points (x,y) inside the square, with x supplied by the Halton sequence in base 2 and y supplied by the Halton sequence in base 3. The square will gradually fill like this:

square1

x = 1/2, y = 1/3


square2

x = 1/4, y = 2/3


square3

x = 3/4, y = 1/9


square4

x = 1/8, y = 4/9


square5

x = 5/8, y = 7/9


square6

x = 3/8, y = 2/9


square7

x = 7/8, y = 5/9


square8

x = 1/16, y = 8/9


square9

x = 9/16, y = 1/27…


square_anim

animated square


Read full page: For Revver and Fevver

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:

All-Base Graph

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…

Amateur ’Grammatics

There is much more to mathematics than mathematics. Like a tree, it has deep roots. Like a tree, it’s affected by its environment. Philosophy of mathematics is concerned with the roots. Psychology of mathematics is concerned with the environment.

On Planet Earth, the environment is human beings. What attracts men and women to the subject? What makes them good or bad at it?And so on. One interesting answer to the first question was supplied by the mathematician Stanislaw Ulam (1909-84), who wrote this in his autobiography:

“In many cases, mathematics is an escape from reality. The mathematician finds his own monastic niche and happiness in pursuits that are disconnected from external affairs. Some practice it as if using a drug.” – Adventures of a Mathematician (1983)

That’s certainly part of maths’ appeal to me: as an escape from reality, or an escape from one reality into another (and deeper). Real life is messy. Maths isn’t, unless you want it to be. But you can find parallels between maths and real life too. In real life, people collect things that they find attractive or interesting: stamps, sea-shells, gems, cigarette-cards, beer-cans and so on. You can collect things in maths too: interesting numbers and number patterns. Recreational maths can feel like looking on a beach for attractive shells and pebbles.

Here’s a good example: digital anagrams, or numbers in different bases whose digits are the same but re-arranged. For example, 13 in base 10 equals 31 in base 4, because 13 = 3 * 4 + 1. To people with the right kind of mind, that’s an interesting and attractive pattern. There are lots more anagrams like that:

1045 = 4501 in base 6
1135 = 5131 in base 6

23 = 32 in base 7
46 = 64 in base 7

1273 = 2371 in base 8
1653 = 3165 in base 8

158 = 185 in base 9
227 = 272 in base 9

196 = 169 in base 11
283 = 238 in base 11

2193 = 1329 in base 12
6053 = 3605 in base 12

43 = 34 in base 13
86 = 68 in base 13

But triple anagrams, involving three bases, seem even more attractive:

913 = 391 in base 16 = 193 in base 26
103462 = 610432 in base 7 = 312046 in base 8
245183 = 413285 in base 9 = 158234 in base 11

And that’s just looking in base 10. If you include all bases, the first double anagram is in fact 21 in base 3 = 12 in base 5 (equals 7 in base 10). The first triple anagram is this:

2C1 in base 13 = 1C2 in base 17 = 12C in base 21 (equals 495 in base 10)

But are there quadruple anagrams, quintuple anagrams and higher? I don’t know. I haven’t found any and it gets harder and harder to search for them, because the bigger n gets, the more bases there are to check. However, I can say one thing for certain: in any given base, anagrams eventually disappear.

To understand why, consider the obvious fact that anagrams have to have the same number of digits in different bases. But the number of digits is a function of the powers of the base. That is, the triple anagram 103462 (see above) has six digits in bases 7, 8 and 10 because 7^5 < 103462 < 7^6, 8^5 < 103462 < 8^6 and 10^5 < 103462 < 10^6. Similarly, the triple anagram 245183 (ditto) has six digits in bases 9, 10 and 11 because 9^5 < 245183 < 9^6, 10^5 < 245183 < 10^6 and 11^5 < 245183 < 11^6:

7^5 < 103462 < 7^6
16807 < 103462 < 117649
8^5 < 103462 < 8^6
32768 < 103462 < 262144
10^5 < 103462 < 10^6
100000 < 103462 < 1000000
9^5 < 245183 < 9^6
59049 < 245183 < 531441
10^5 < 245183 < 10^6
100000 < 245183 < 1000000
11^5 < 245183 < 11^6
161051 < 245183 < 1771561

In other words, for some n the number-lengths of bases 7 and 8 overlap the number-lengths of base 10, which overlap the number-lengths of bases 9 and 11. But eventually, as n gets larger, the number-lengths of base 10 will fall permanently below the number-lengths of bases 7, 8 and 9, just as the number-lengths of base 11 will fall permanently below the number-lengths of base 10.

To see this in action, consider the simplest example: number-lengths in bases 2 and 3. There is no anagram involving these two bases, because only two numbers have the same number of digits in both: 1 and 3 = 11 in base 2 = 10 in base 3. After that, n in base 2 always has more digits than n in base 3:

2^0 = 1 in base 2 (number-length=1) = 1 in base 3 (l=1)
2^1 = 2 = 10 in base 2 (number-length=2) = 2 in base 3 (l=1)
2^2 = 4 = 100 in base 2 (l=3) = 11 in base 3 (l=2)
2^3 = 8 = 1000 in base 2 = 22 in base 3 (l=2)
2^4 = 16 = 10000 in base 2 = 121 in base 3 (l=3)
2^5 = 32 = 1012 in base 3 (l=4)
2^6 = 64 = 2101 in base 3 (l=4)
2^7 = 128 = 11202 in base 3 (l=5)
2^8 = 256 = 100111 in base 3 (l=6)
2^9 = 512 = 200222 in base 3 (l=6)
2^10 = 1024 = 1101221 in base 3 (l=7)

Now consider bases 3 and 4. Here is an anagram using these bases: 211 in base 3 = 112 in base 4 = 22. There are no more anagrams and eventually there’s no more chance for them to occur, because this happens as n gets larger:

3^0 = 1 in base 3 (number-length=1) = 1 in base 4 (l=1)
3^1 = 3 = 10 in base 3 (number-length=2) = 3 in base 4 (l=1)
3^2 = 9 = 100 in base 3 (l=3) = 21 in base 4 (l=2)
3^3 = 27 = 1000 in base 3 (l=4) = 123 in base 4 (l=3)
3^4 = 81 = 10000 in base 3 (l=5) = 1101 in base 4 (l=4)
3^5 = 243 = 100000 in base 3 (l=6) = 3303 in base 4 (l=4)
3^6 = 729 = 23121 in base 4 (l=5)
3^7 = 2187 = 202023 in base 4 (l=6)
3^8 = 6561 = 1212201 in base 4 (l=7)
3^9 = 19683 = 10303203 in base 4 (l=8)
3^10 = 59049 = 32122221 in base 4 (l=8)
3^11 = 177147 = 223033323 in base 4 (l=9)
3^12 = 531441 = 2001233301 in base 4 (l=10)
3^13 = 1594323 = 12011033103 in base 4 (l=11)
3^14 = 4782969 = 102033231321 in base 4 (l=12)
3^15 = 14348907 = 312233021223 in base 4 (l=12)
3^16 = 43046721 = 2210031131001 in base 4 (l=13)
3^17 = 129140163 = 13230220113003 in base 4 (l=14)
3^18 = 387420489 = 113011321011021 in base 4 (l=15)
3^19 = 1162261467 = 1011101223033123 in base 4 (l=16)
3^20 = 3486784401 = 3033311001232101 in base 4 (l=16)

When n is sufficiently large, it always has fewer digits in base 4 than in base 3. And the gap gets steadily bigger. When n doesn’t have the same number of digits in two bases, it can’t be an anagram. A similar number-length gap eventually appears in bases 4 and 5, but the anagrams don’t run out as quickly there:

103 in base 5 = 130 in base 4 = 28
1022 in base 5 = 2021 in base 4 = 137
1320 in base 5 = 3102 in base 4 = 210
10232 in base 5 = 22310 in base 4 = 692
10332 in base 5 = 23031 in base 4 = 717
12213 in base 5 = 32211 in base 4 = 933
100023 in base 5 = 301002 in base 4 = 3138
100323 in base 5 = 302031 in base 4 = 3213
102131 in base 5 = 311120 in base 4 = 3416
102332 in base 5 = 312023 in base 4 = 3467
103123 in base 5 = 313102 in base 4 = 3538
1003233 in base 5 = 3323010 in base 4 = 16068

Base 10 isn’t exempt. Eventually it must outshrink base 9 and be outshrunk by base 11, so what is the highest 9:10 anagram and highest 10:11 anagram? I don’t know: my maths isn’t good enough for me to find out quickly. But using machine code, I’ve found these large anagrams:

205888888872731 = 888883178875022 in base 9
1853020028888858 = 8888888525001032 in base 9
16677181388880888 = 88888888170173166 in base 9

999962734025 = 356099992472 in base 11
9999820360965 = 3205999998606 in base 11
99999993520348 = 29954839390999 in base 11

Note how the digits of n in the lower base are increasing as the digits of n in the higher base are decreasing. Eventually, n in the lower base will always have more digits than n in the higher base. When that happens, there will be no more anagrams.

Some triple anagrams

2C1 in base 13 = 1C2 in base 17 = 12C in base 21 (n=495 = 3^2*5*11)
912 in base 10 = 219 in base 21 = 192 in base 26 (2^4*3*19)
913 in base 10 = 391 in base 16 = 193 in base 26 (11*83)
4B2 in base 15 = 42B in base 16 = 24B in base 22 (n=1067 = 11*97)
5C1 in base 17 = 51C in base 18 = 1C5 in base 35 (n=1650 = 2*3*5^2*11)
3L2 in base 26 = 2L3 in base 31 = 23L in base 35 (n=2576 = 2^4*7*23)
3E1 in base 31 = 1E3 in base 51 = 13E in base 56 (n=3318 = 2*3*7*79)
531 in base 29 = 351 in base 37 = 135 in base 64 (n=4293 = 3^4*53)
D53 in base 18 = 53D in base 29 = 35D in base 37 (n=4305 = 3*5*7*41)
53I in base 29 = 3I5 in base 35 = 35I in base 37 (n=4310 = 2*5*431)
825 in base 25 = 582 in base 31 = 258 in base 49 (n=5055 = 3*5*337)
6S2 in base 31 = 2S6 in base 51 = 26S in base 56 (n=6636 = 2^2*3*7*79)
D35 in base 23 = 5D3 in base 36 = 3D5 in base 46 (n=6951 = 3*7*331)
3K1 in base 49 = 31K in base 52 = 1K3 in base 81 (n=8184 = 2^3*3*11*31)
A62 in base 29 = 6A2 in base 37 = 26A in base 64 (n=8586 = 2*3^4*53)
9L2 in base 30 = 92L in base 31 = 2L9 in base 61 (n=8732 = 2^2*37*59)
3W1 in base 49 = 1W3 in base 79 = 13W in base 92 (n=8772 = 2^2*3*17*43)
G4A in base 25 = AG4 in base 31 = 4AG in base 49 (n=10110 = 2*3*5*337)
J10 in base 25 = 1J0 in base 100 = 10J in base 109 (n=11900 = 2^2*5^2*7*17)
5[41]1 in base 46 = 1[41]5 in base 93 = 15[41] in base 109 (n=12467 = 7*13*137)
F91 in base 29 = 9F1 in base 37 = 19F in base 109 (n=12877 = 79*163)
F93 in base 29 = 9F3 in base 37 = 39F in base 64 (n=12879 = 3^5*53)
AP4 in base 35 = A4P in base 36 = 4AP in base 56 (n=13129 = 19*691)
BP2 in base 36 = B2P in base 37 = 2PB in base 81 (n=15158 = 2*11*13*53)
O6F in base 25 = FO6 in base 31 = 6FO in base 49 (n=15165 = 3^2*5*337)
FQ1 in base 31 = 1QF in base 111 = 1FQ in base 116 (n=15222 = 2*3*43*59)
B74 in base 37 = 7B4 in base 46 = 47B in base 61 (n=15322 = 2*47*163)

Can You Dij It? #1

The most powerful drug in the world is water. The second most powerful is language. But everyone’s on them, so nobody realizes how powerful they are. Well, you could stop drinking water. Then you’d soon realize its hold on the body and the brain.

But you can’t stop using language. Try it. No, the best way to realize the power of language is to learn a new one. Each is a feast with different flavours. New alphabets are good too. The Devanagari alphabet is one of the strongest, but if you want it in refined form, try the phonetic alphabet. It will transform the way you see the world. That’s because it will make you conscious of what you’re already subconsciously aware of.

But “language” is a bigger category that it used to be. Nowadays we have computer languages too. Learning one is another way of transforming the way you see the world. And like natural languages – French, Georgian, Tagalog – they come in different flavours. Pascal is not like Basic is not like C is not like Prolog. But all of them seem to put you in touch with some deeper aspect of reality. Computer languages are like mathemagick: a way to give commands to something immaterial and alter the world by the application of will.

That feeling is at its strongest when you program with machine code, the raw instructions used by the electronics of a computer. At its most fundamental, machine code is simply a series of binary numbers controlling how a computer processes other binary numbers. You can memorize and use those code-numbers, but it’s easier to use something like assembly language, which makes machine-code friendlier for human beings. But it still looks very odd to the uninitiated:

setupnum:
xor ax,ax
xor bp,bp
mov cx,20
clearloop:
mov [di+bp],ax
add bp,2
loop clearloop
ret

That’s almost at the binary bedrock. And machine code is fast. If a fast higher-level language like C feels like flying a Messerschmitt 262, which was a jet-plane, machine-code feels like flying a Messerschmitt 163, which was a rocket-plane. A very fast and very dangerous rocket-plane.

I’m not good at programming languages, least of all machine code, but they are fun to use, quite apart from the way they make you feel as though you’re in touch with a deeper aspect of reality. They do that because the world is mathematics at its most fundamental level, I think, and computer languages are a form of mathematics.

Their mathematical nature is disguised in a lot of what they’re used for, but I like to use them for recreational mathematics. Machine-code is useful when you need a lot of power and speed. For example, look at these digits:

1, 2, 3, 4, 5, 6, 7, 8, 9, 1*, 0*, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 2, 9, 3, 0, 3, 1, 3, 2, 3, 3, 3, 4, 3, 5, 3, 6*, 3*, 7, 3, 8, 3, 9, 4, 0, 4, 1, 4, 2, 4…

They’re what the Online Encyclopedia of Integer Sequences (OEIS) calls “the almost natural numbers” (sequence A007376) and you generate them by writing the standard integers – 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13… – and then separating each digit with a comma: 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 0, 1, 1, 1, 2, 1, 3… The commas give them some interesting twists. In a list of the standard integers, the 1st entry is 1, the 10th entry is 10, the 213rd entry is 213, the 987,009,381th entry is 987,009,381, and so on.

But that doesn’t work with the almost natural numbers. The 10th entry is 1, not 10, and the 11th entry is 0, not 11. But the 10th entry does begin the sequence (1, 0). I wondered whether that happened again. It does. The 63rd entry in the almost natural numbers begins the sequence (6, 3) – see the asterisks in the sequence above.

This happens again at the 3105th entry, which begins the sequence (3, 1, 0, 5). After that the gaps get bigger, which is where machine code comes in. An ordinary computer-language takes a long time to reach the 89,012,345,679th entry in the almost natural numbers. Machine code is much quicker, which is why I know that the 89,012,345,679th entry begins the sequence (8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 9):

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 63, 3105, 43108, 77781, 367573, 13859021, 77911127, 911360799, 35924813703, 74075186297, 89012345679…

And an ordinary computer-language might give you the impression that base 9 doesn’t have numbers like these (apart from the trivial 1, 2, 3, 4, 5, 6, 7, 8, 10…). But it does. 63 in base 10 is a low-hanging fruit: you could find it working by hand. In base 9, the fruit are much higher-hanging. But machine code plucks them with almost ridiculous ease:

1, 2, 3, 4, 5, 6, 7, 8, 10, 570086565, 655267526, 2615038272, 4581347024, 5307541865, 7273850617, 7801234568…

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].

Magistra Rules the Waves

One of my favourite integer sequences has the simple formula n(i) = n(i-1) + digitsum(n(i-1)). If it’s seeded with 1, its first few terms go like this:

n(1) = 1
n(2) = n(1) + digitsum(n(1)) = 1 + digitsum(1) = 2
n(3) = 2 + digitsum(2) = 4
n(4) = 4 + digitsum(4) = 8
n(5) = 8 + digitsum(8) = 16
n(6) = 16 + digitsum(16) = 16 + 1+6 = 16 + 7 = 23
n(7) = 23 + digitsum(23) = 23 + 2+3 = 23 + 5 = 28
n(8) = 28 + digitsum(28) = 28 + 2+8 = 28 + 10 = 38

As a sequence, it looks 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…

Given a number at random, is there a quick way to say whether it appears in the sequence seeded with 1? Not that I know, with one exception. If the number is divisible by 3, it doesn’t appear, at least in base 10. In base 2, that rule doesn’t apply:

n(1) = 1
n(2) = 1 + digitsum(1) = 10 = 1 + 1 = 2
n(3) = 10 + digitsum(10) = 10 + 1 = 11 = 2 + 1 = 3
n(4) = 11 + digitsum(11) = 11 + 1+1 = 101 = 3 + 2 = 5
n(5) = 101 + digitsum(101) = 101 + 1+0+1 = 111 = 5 + 2 = 7
n(6) = 111 + digitsum(111) = 111 + 11 = 1010 = 7 + 3 = 10
n(7) = 1010 + digitsum(1010) = 1010 + 10 = 1100 = 10 + 2 = 12
n(8) = 1100 + digitsum(1100) = 1100 + 10 = 1110 = 12 + 2 = 14

1, 2, 3, 5, 7, 10, 12, 14, 17, 19, 22, 25, 28, 31, 36, 38, 41, 44, 47, 52, 55, 60, 64, 65, 67, 70, 73, 76, 79, 84, 87, 92, 96, 98, 101, 105, 109, 114, 118, 123, 129, 131, 134, 137, 140, 143, 148, 151, 156, 160, 162, 165, 169, 173, 178, 182, 187, 193, 196, 199, 204, 208, 211, 216, 220, 225, 229, 234, 239, 246, 252, 258, 260, 262, 265, 268, 271, 276, 279, 284, 288, 290, 293, 297, 301, 306, 310, 315, 321, 324, 327, 332, 336, 339, 344, 348, 353, 357, 362, 367, 374…

What patterns are there in these sequences? It’s easier to check when they’re represented graphically, so I converted them into patterns à la the Ulam spiral, where n is represented as a dot on a spiral of integers. This is the spiral for base 10:

ulambase10Base 10


And these are the spirals for bases 2 and 3:

ulambase2

Base 2


ulambase3

Base 3


These sequences look fairly random to me: there are no obvious patterns in the jumps from n(i) to n(i+1), i.e. in the values for digitsum(n(i)). Now try the spirals for bases 9 and 33:

ulambase9

Base 9


ulambase33

Base 33


Patterns have appeared: there is some regularity in the jumps. You can see these regularities more clearly if you represent digitsum(n(i)) as a graph, with n(i) on the x axis and digitsum(n(i)) on the y axis. If the graph starts with n(i) = 1 on the lower left and proceeds left-right, left-right up the screen, it looks like this in base 10:

base10

Base 10 (click to enlarge)


Here are bases 2 and 3:

base2

Base 2


base3

Base 3


The jumps seem fairly random. Now try bases 9, 13, 16, 17, 25, 33 and 49:

base9

Base 9


base13

Base 13


base16

Base 16


base17

Base 17


base25

Base 25


base33

Base 33


base49

Base 49


In some bases, the formula n(i) = n(i-1) + digitsum(n(i-1)) generates mild randomness. In others, it generates strong regularity, like waves rolling ashore under a steady wind. I don’t understand why, but regularity seems to occur in bases that are one more than a power of 2 and also in some bases that are primes or squares.


Elsewhere other-posted:

Mathematica Magistra Mundi
8200_idf_insignia