Wake the Snake

In my story “Kopfwurmkundalini”, I imagined the square root of 2 as an infinitely long worm or snake whose endlessly varying digit-segments contained all stories ever (and never) written:

• √2 = 1·414213562373095048801688724209698078569671875376948073…

But there’s another way to get all stories ever written from the number 2. You don’t look at the root(s) of 2, but at the powers of 2:

• 2 = 2^1 = 2
• 4 = 2^2 = 2*2
• 8 = 2^3 = 2*2*2
• 16 = 2^4 = 2*2*2*2
• 32 = 2^5 = 2*2*2*2*2
• 64 = 2^6 = 2*2*2*2*2*2
• 128 = 2^7 = 2*2*2*2*2*2*2
• 256 = 2^8 = 2*2*2*2*2*2*2*2
• 512 = 2^9 = 2*2*2*2*2*2*2*2*2
• 1024 = 2^10
• 2048 = 2^11
• 4096 = 2^12
• 8192 = 2^13
• 16384 = 2^14
• 32768 = 2^15
• 65536 = 2^16
• 131072 = 2^17
• 262144 = 2^18
• 524288 = 2^19
• 1048576 = 2^20
• 2097152 = 2^21
• 4194304 = 2^22
• 8388608 = 2^23
• 16777216 = 2^24
• 33554432 = 2^25
• 67108864 = 2^26
• 134217728 = 2^27
• 268435456 = 2^28
• 536870912 = 2^29
• 1073741824 = 2^30
[...]

The powers of 2 are like an ever-lengthening snake swimming across a pool. The snake has an endlessly mutating head and a rhythmically waving tail with a regular but ever-more complex wake. That is, the leading digits of 2^p don’t repeat but the trailing digits do. Look at the single final digit of 2^p, for example:

• 02 = 2^1
• 04 = 2^2
• 08 = 2^3
• 16 = 2^4
• 32 = 2^5
• 64 = 2^6
• 128 = 2^7
• 256 = 2^8
• 512 = 2^9
• 1024 = 2^10
• 2048 = 2^11
• 4096 = 2^12
• 8192 = 2^13
• 16384 = 2^14
• 32768 = 2^15
• 65536 = 2^16
• 131072 = 2^17
• 262144 = 2^18
• 524288 = 2^19
• 1048576 = 2^20
• 2097152 = 2^21
• 4194304 = 2^22
[...]

The final digit of 2^p falls into a loop: 2 → 4 → 8 → 6 → 2 → 4→ 8…

Now try the final two digits of 2^p:

02 = 2^1
04 = 2^2
08 = 2^3
16 = 2^4
32 = 2^5
64 = 2^6
• 128 = 2^7
• 256 = 2^8
• 512 = 2^9
• 1024 = 2^10
• 2048 = 2^11
• 4096 = 2^12
• 8192 = 2^13
• 16384 = 2^14
• 32768 = 2^15
• 65536 = 2^16
• 131072 = 2^17
• 262144 = 2^18
• 524288 = 2^19
• 1048576 = 2^20
• 2097152 = 2^21
• 4194304 = 2^22
• 8388608 = 2^23
• 16777216 = 2^24
• 33554432 = 2^25
• 67108864 = 2^26
• 134217728 = 2^27
• 268435456 = 2^28
• 536870912 = 2^29
• 1073741824 = 2^30
[...]

Now there’s a longer loop: 02 → 04 → 08 → 16 → 32 → 64 → 28 → 56 → 12 → 24 → 48 → 96 → 92 → 84 → 68 → 36 → 72 → 44 → 88 → 76 → 52 → 04 → 08 → 16 → 32 → 64 → 28… Any number of trailing digits, 1 or 2 or one trillion, falls into a loop. It just takes longer as the number of trailing digits increases.

That’s the tail of the snake. At the other end, the head of the snake, the digits don’t fall into a loop (because of the carries from the lower digits). So, while you can get only 2, 4, 8 and 6 as the final digits of 2^p, you can get any digit but 0 as the first digit of 2^p. Indeed, I conjecture (but can’t prove) that not only will all integers eventually appear as the leading digits of 2^p, but they will do so infinitely often. Think of a number and it will appear as the leading digits of 2^p. Let’s try the numbers 1, 12, 123, 1234, 12345…:

16 = 2^4
128 = 2^7
12379400392853802748... = 2^90
12340799625835686853... = 2^1545
12345257952011458590... = 2^34555
12345695478410965346... = 2^63293
12345673811591269861... = 2^4869721
12345678260232358911... = 2^5194868
12345678999199154389... = 2^62759188

But what about the numbers 9, 98, 987, 986, 98765… as leading digits of 2^p? They don’t appear as quickly:

9007199254740992 = 2^53
98079714615416886934... = 2^186
98726397006685494828... = 2^1548
98768356967522174395... = 2^21257
98765563827287722773... = 2^63296
98765426081858871289... = 2^5194871
98765430693066680199... = 2^11627034
98765432584491513519... = 2^260855656
98765432109571471006... = 2^1641098748

Why do fragments of 123456789 appear much sooner than fragments of 987654321? Well, even though all integers occur infinitely often as leading digits of 2^p, some integers occur more often than others, as it were. The leading digits of 2^p are actually governed by a fascinating mathematical phenomenon known as Benford’s law, which states, for example, that the single first digit, d, will occur with the frequency log10(1 + 1/d). Here are the actual frequencies of 1..9 for all powers of 2 up to 2^101000, compared with the estimate by Benford’s law:

1: 30% of leading digits ↔ 30.1% estimated
2: 17.55% ↔ 17.6%
3: 12.45% ↔ 12.49%
4: 09.65% ↔ 9.69%
5: 07.89% ↔ 7.92%
6: 06.67% ↔ 6.69%
7: 05.77% ↔ 5.79%
8: 05.09% ↔ 5.11%
9: 04.56% ↔ 4.57%

Because (inter alia) 1 appears as the first digit of 2^p far more often than 9 does, the fragments of 123456789 appear faster than the fragments of 987654321. Mutatis mutandis, the same applies in all other bases (apart from bases that are powers of 2, where there’s a single leading digit, 1, 2, 4, 8…, followed by 0s). But although a number like 123456789 occurs much frequently than 987654321 in 2^p expressed in base 10 (and higher), both integers occur infinitely often.

As do all other integers. And because stories can be expressed as numbers, all stories ever (and never) written appear in the powers of 2. Infinitely often. You’ll just have to trim the tail of the story-snake.

Block and Goal

123456789. How many ways are there to insert + and – between the numbers and create a formula for 100? With pen and ink it takes a long time to answer. With programming, the answer will flash up in an instant:

01. 1 + 2 + 3 - 4 + 5 + 6 + 78 + 9 = 100
02. 1 + 2 + 34 - 5 + 67 - 8 + 9 = 100
03. 1 + 23 - 4 + 5 + 6 + 78 - 9 = 100
04. 1 + 23 - 4 + 56 + 7 + 8 + 9 = 100
05. 12 - 3 - 4 + 5 - 6 + 7 + 89 = 100
06. 12 + 3 + 4 + 5 - 6 - 7 + 89 = 100
07. 12 + 3 - 4 + 5 + 67 + 8 + 9 = 100
08. 123 - 4 - 5 - 6 - 7 + 8 - 9 = 100
09. 123 + 4 - 5 + 67 - 89 = 100
10. 123 + 45 - 67 + 8 - 9 = 100
11. 123 - 45 - 67 + 89 = 100

And the beauty of programming is that you can easily generalize the problem to other bases. In base b, how many ways are there to insert + and – in the block [12345…b-1] to create a formula for b^2? When b = 10, the answer is 11. When b = 11, it’s 42. Here are two of those formulae in base-11:

123 - 45 + 6 + 7 - 8 + 9 + A = 100[b=11]
146 - 49 + 6 + 7 - 8 + 9 + 10 = 121

123 + 45 + 6 + 7 - 89 + A = 100[b=11]
146 + 49 + 6 + 7 - 97 + 10 = 121

When b = 12, it’s 51. Here are two of the formulae:

123 + 4 + 5 + 67 - 8 - 9A + B = 100[b=12]
171 + 4 + 5 + 79 - 8 - 118 + 11 = 144

123 + 4 + 56 + 7 - 89 - A + B = 100[b=12]
171 + 4 + 66 + 7 - 105 - 10 + 11 = 144

So that’s 11 formulae in base-10, 42 in base-11 and 51 in base-12. So what about base-13? The answer may be surprising: in base-13, there are no +/- formulae for 13^2 = 169 using the numbers 1 to 12. Nor are there any formulae in base-9 for 9^2 = 81 using the numbers 1 to 8. If you reverse the block, 987654321, the same thing happens. Base-10 has 15 formulae, base-11 has 54 and base-12 has 42. Here are some examples:

9 - 8 + 7 + 65 - 4 + 32 - 1 = 100
98 - 76 + 54 + 3 + 21 = 100

A9 + 87 - 65 + 4 - 3 - 21 = 100[b=11]
119 + 95 - 71 + 4 - 3 - 23 = 121

BA - 98 + 76 - 5 - 4 + 32 - 1 = 100[b=12]
142 - 116 + 90 - 5 - 4 + 38 - 1 = 144

But base-9 and base-13 again have no formulae. What’s going on? Is it a coincidence that 9 and 13 are each one more than a multiple of 4? No. Base-17 also has no formulae for b^2 = 13^2 = 169. Here is the list of formulae for bases-7 thru 17:

1, 2, 0, 11, 42, 51, 0, 292, 1344, 1571, 0 (block = 12345...)
3, 2, 0, 15, 54, 42, 0, 317, 1430, 1499, 0 (block = ...54321)

To understand what’s going on, consider any sequence of consecutive integers starting at 1. The number of odd integers in the sequence must always be greater than or equal to the number of even integers:

1, 2 (1 odd : 1 even)
1, 2, 3 (2 odds : 1 even)
1, 2, 3, 4 (2 : 2)
1, 2, 3, 4, 5 (3 : 2)
1, 2, 3, 4, 5, 6 (3 : 3)
1, 2, 3, 4, 5, 6, 7 (4 : 3)
1, 2, 3, 4, 5, 6, 7, 8 (4 : 4)

The odd numbers in a sequence determine the parity of the sum, that is, whether it is odd or even. For example:

1 + 2 = 3 (1 odd number)
1 + 2 + 3 = 6 (2 odd numbers)
1 + 2 + 3 + 4 = 10 (2 odd numbers)
1 + 2 + 3 + 4 + 5 = 15 (3 odd numbers)
1 + 2 + 3 + 4 + 5 + 6 = 21 (3 odd numbers)
1 + 2 + 3 + 4 + 5 + 6 + 7 = 28 (4 odd numbers)

If there is an even number of odd numbers, the sum will be even; if there is an odd number, the sum will be odd. Consider sequences that end in a multiple of 4:

1, 2, 3, 4 → 2 odds : 2 evens
1, 2, 3, 4, 5, 6, 7, 8 → 4 : 4
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 → 6 : 6

Such sequences always contain an even number of odd numbers. Now, consider these formulae in base-10:

1. 12 + 3 + 4 + 56 + 7 + 8 + 9 = 99
2. 123 - 45 - 67 + 89 = 100
3. 123 + 4 + 56 + 7 - 89 = 101

They can be re-written like this:

1. 1×10^1 + 2×10^0 + 3×10^0 + 4×10^0 + 5×10^1 + 6×10^0 + 7×10^0 + 8×10^0 + 9×10^0 = 99

2. 1×10^2 + 2×10^1 + 3×10^0 – 4×10^1 – 5×10^0 – 6×10^1 – 7×10^0 + 8×10^1 + 9×10^0 = 100

3. 1×10^2 + 2×10^1 + 3×10^0 + 4×10^0 + 5×10^1 + 6×10^1 + 7×10^0 – 8×10^1 – 9×10^0 = 101

In general, the base-10 formulae will take this form:

1×10^a +/- 2×10^b +/- 3×10^c +/– 4×10^d +/– 5×10^e +/– 6×10^f +/– 7×10^g +/– 8×10^h +/– 9×10^i = 100

It’s important to note that the exponent of 10, or the power to which it is raised, determines whether an odd number remains odd or becomes even. For example, 3×10^0 = 3×1 = 3, whereas 3×10^1 = 3×10 = 30 and 3×10^2 = 3×100 = 300. Therefore the number of odd numbers in a base-10 formula can vary and so can the parity of the sum. Now consider base-9. When you’re trying to find a block-formula for 9^2 = 81, the formula will have to take this form:

1×9^a +/- 2×9^b +/- 3×9^c +/- 4×9^d +/- 5×9^e +/- 6×9^f +/- 7×9^g +/- 8×9^h = 81

But no such formula exists for 81 (with standard exponents). It’s now possible to see why this is so. Unlike base-10, the odd numbers in the formula will remain odd what the power of 9. For example, 3×9^0 = 3×1 = 3, 3×9^1 = 3×9 = 27 and 3×9^2 = 3×81 = 243. Therefore base-9 formulae will always contain four odd numbers and will always produce an even number. Odd numbers in base-2 always end in 1, even numbers always end in 0. Therefore, to determine the parity of a sum of integers, convert the integers to base-2, discard all but the final digit of each integer, then sum the 1s. In a base-9 formula, these are the four possible results:

1 + 1 + 1 + 1 = 4
1 + 1 + 1 - 1 = 2
1 + 1 - 1 - 1 = 0
1 - 1 - 1 - 1 = -2

The sum represents the parity of the answer, which is always even. Similar reasoning applies to base-13, base-17 and all other base-[b=4n+1].