Thursday, 12 September 2019

An Algorithm

Figure 1
Algorithms seemingly rule the world. Today I was confronted with my number of the day (25729) and was struggling to find something of interest in it. All I came up with for my Twitter post is shown in Figure 1. Clearly I was clutching at straws but later I noticed an interesting pattern. 2 + 5 is 7 and 7 - 5 is 2 and 7 + 2 is 9. What's happening here can be represented as an algorithm:

ADD the 1st digit to the 2nd digit and put the result to the right of the two digits to form a new number (here the addition yields 7 and so the new number is 257).

SUBTRACT the 2nd digit from the 3rd digit and place the result to the right again to form a new number (here the result of the subtraction is 2 and so the new number is 2572).

ADD the 3rd digit to the 4th digit and place the result to the right again to form a new number (here the result of the addition is 9 and so the new number is 25729).

If this process were repeated two more times, the result would be 25729716. This leads to a problem because with 16 comes a jump in the number of digits. It's probably best to make the rule such that, if the result of the addition is a two digit number, then 10 is subtracted so that a one digit number is returned. This would yield 6 in the case of 16. The number is now 2572976.

Here again we have a problem because subtracting 7 from 6 yield -1. If we stick to our modulus 10 approach, then -1 is really 9. Thus the number becomes 25729769.

The algorithm is thus a repeating addition and subtraction of digit pairs, starting with the addition of the first two digits. What I did next was to investigate what happens to 25729769 as the process continues.

I found that once the digit stream reached 120 digits, the cycle was complete. This could be expressed in terms of a trajectory of length 120. I was interested in what happened with other pairs of starting digits.

There are 90 possibilities starting with 10 (I didn't want leading zeroes) and ending with 99.

Here is what I found (any numbers omitted have a trajectory of 120):

12 --> 24 digits before repeating
17 --> 24 digits before repeating
20 --> 40 digits before repeating
22 --> 40 digits before repeating
24 --> 8 digits before repeating
26 --> 40 digits before repeating
28 --> 40 digits before repeating
29 --> 24 digits before repeating
31 --> 24 digits before repeating
36 --> 24 digits before repeating
40 --> 40 digits before repeating
42 --> 40 digits before repeating
43 --> 24 digits before repeating
44 --> 40 digits before repeating
46 --> 40 digits before repeating
48 --> 8 digits before repeating
50 --> 3 digits before repeating
51 --> 3 digits before repeating
52 --> 3 digits before repeating
53 --> 3 digits before repeating
54 --> 3 digits before repeating
55 --> 3 digits before repeating
56 --> 3 digits before repeating
57 --> 3 digits before repeating
58 --> 3 digits before repeating
59 --> 3 digits before repeating
60 --> 40 digits before repeating
62 --> 8 digits before repeating
64 --> 40 digits before repeating
66 --> 40 digits before repeating
67 --> 24 digits before repeating
68 --> 40 digits before repeating
74 --> 24 digits before repeating
79 --> 24 digits before repeating
80 --> 40 digits before repeating
81 --> 24 digits before repeating
82 --> 40 digits before repeating
84 --> 40 digits before repeating
86 --> 8 digits before repeating
88 --> 40 digits before repeating
93 --> 24 digits before repeating
98 --> 24 digits before repeating

There are 90 numbers between 10 and 99:
  • 48 of them have trajectories of 120 digits
  • 42 of them have trajectories other than 120
Of these 42:
  • 10 have trajectories of 3 (50 to 59)
  • 4 have trajectories of 8 (24, 48, 62, 86)
  • 12 have trajectories of 24
    (12, 17, 29, 31, 36, 43, 67, 74, 79, 81, 93, 98)
  • 16 have trajectories of 40
    (20, 22, 26, 28, 40, 42, 44, 46, 60, 64, 66, 68, 80, 82, 84, 88)
The trajectories of 3, 8, 24 and 40 are all factors of 120 (3 x 40 = 120, 8 x 15 = 120, 24 x 5 = 120, 40 x 3 = 120)

Here is the SageMath code that I used (permalink):

a=2
b=5
number=[a,b]
for i in [1..65]:
    c=(a+b)%10
    number.append(c)
    d=(c-b)%10
    number.append(d)
    a=c
    b=d
string=""
for i in range(0,len(number)):
    string+=str(number[i])
print string 
item=str(number[0])+str(number[1])+str(number[2])
string2=''
for i in range(3,len(number)):
    string2+=str(number[i])
w=Word(string2)
print str(number[0])+str(number[1]),"-->",w.find(item)+3,"digits before repeating"

This produced an output of:

257297695615617637033033639659459439235275279219011011213253853813415495493473077077471451651671875835831891099099897857257297695615
25 --> 120 digits before repeating

The lesson to be drawn from this is that there is something of interest lurking in every number. It's up to us to see it. The fault is in ourselves, not the number. Notice also that the number 42 (the subject of my previous post) makes an appearance in this post (as the number of trajectories between 10 and 99 that are not equal to 120). The real mystery is why 120 is the upper limit and why there isn't a spread of trajectories rather than a clumping of them at 3, 8, 24, 40 and 120.

No comments:

Post a Comment