Spijit

The only two digits found in all standard bases are 1 and 0. But they behave quite differently. Suppose you take the integers 1 to 100 and compare the number of 1s and 0s in the representation of each integer, n, in bases 2 to n-1. For example, 10 would look like this:

1010 in base 2
101 in base 3
22 in base 4
20 in base 5
14 in base 6
13 in base 7
12 in base 8
11 in base 9

So there are nine 1s and four 0s. If you check 1 to 100 using this all-base function, the count of 1s goes like this:

1, 1, 2, 3, 5, 5, 8, 5, 9, 9, 11, 10, 15, 12, 14, 13, 15, 12, 17, 14, 20, 19, 20, 15, 23, 19, 22, 22, 25, 24, 31, 21, 25, 24, 24, 27, 33, 27, 31, 29, 34, 29, 36, 30, 34, 35, 34, 30, 40, 33, 36, 35, 38, 34, 42, 37, 43, 40, 41, 37, 48, 39, 42, 42, 44, 43, 48, 43, 47, 46, 51, 42, 53, 44, 48, 50, 51, 50, 55, 48, 59, 55, 55, 54, 64, 57, 57, 55, 60, 57, 68, 60, 64, 63, 64, 59, 68, 58, 61, 63.

And the count of 0s goes like this:

0, 1, 0, 2, 1, 2, 0, 4, 4, 4, 2, 5, 1, 2, 2, 7, 4, 8, 4, 7, 4, 3, 1, 8, 4, 4, 6, 8, 4, 7, 1, 10, 8, 7, 7, 12, 5, 6, 5, 10, 4, 8, 2, 6, 7, 4, 2, 12, 6, 9, 7, 8, 4, 11, 6, 10, 5, 4, 2, 12, 2, 3, 5, 14, 11, 13, 7, 10, 8, 11, 5, 17, 7, 8, 10, 10, 8, 10, 4, 13, 12, 10, 8, 16, 8, 7, 7, 12, 6, 14, 6, 8, 5, 4, 4, 16, 6, 10, 11, 15.

The bigger the numbers get, the bigger the discrepancies get. Sometimes the discrepancy is dramatic. For example, suppose you represented the prime 1014719 in bases 2 to 1014718. How 0s would there be? And how many 1s? There are exactly nine zeroes:

1014719 = 11110111101110111111 in base 2 = 1220112221012 in base 3 = 40B27B in base 12 = 1509CE in base 15 = 10[670] in base 1007.

But there are 507723 ones. The same procedure applied to the next integer, 1014720, yields 126 zeroes and 507713 ones. However, there is a way to see that 1s and 0s in the all-base representation are behaving in a similar way. To do this, imagine listing the individual digits of n in bases 2 to n-1 (or just base 2, if n <= 3). When the digits aren’t individual they look like this:

1 = 1 in base 2
2 = 10 in base 2
3 = 11 in base 2
4 = 100 in base 2; 11 in base 3
5 = 101 in base 2; 12 in base 3; 11 in base 4
6 = 110 in base 2; 20 in base 3; 12 in base 4; 11 in base 5
7 = 111 in base 2; 21 in base 3; 13 in base 4; 12 in base 5; 11 in base 6
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
9 = 1001 in base 2; 100 in base 3; 21 in base 4; 14 in base 5; 13 in base 6; 12 in base 7; 11 in base 8
10 = 1010 in base 2; 101 in base 3; 22 in base 4; 20 in base 5; 14 in base 6; 13 in base 7; 12 in base 8; 11 in base 9

So the list would look like this:

1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 2, 1, 1, 1, 1, 0, 2, 0, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 3, 1, 2, 1, 1, 1, 0, 0, 0, 2, 2, 2, 0, 1, 3, 1, 2, 1, 1, 1, 0, 0, 1, 1, 0, 0, 2, 1, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 1, 0, 1, 0, 1, 2, 2, 2, 0, 1, 4, 1, 3, 1, 2, 1, 1

Suppose that these digits are compared against the squares of a counter-clockwise spiral on a rectangular grid. If the spiral digit is equal to 1, the square is filled in; if the spijit is not equal to 1, the square is left blank. The 1-spiral looks like this:

Now try zero. If the spijit is equal to 0, the square is filled in; if not, the square is left blank. The 0-spiral looks like this:

And here’s an animated gif of the n-spiral for n = 0..9:

N-route

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

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

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

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

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

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

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

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

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

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

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

(Please open in new window etc)

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

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

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

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

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

And what about cubes, hypercubes and higher?