[Math Lair] Loops

Math Lair Home > Topics > Loops

"Mathematicians have their own version of stunt flying. They use numbers instead of airplanes. (Wouldn't you know it!) They get their thrills from numerical loopings and from discovering patterns while they're doing their tricks. One person's pattern is another's loop-the-loop."
Math for Smarty Pants
Here are some interesting looping techniques (involving starting with some number and repeating some process on it over and over again) that you might want to try out:

This first activity was devised by Stanislav Ulam. Start with any number you like and follow the following rules:

  1. If your number is even, divide it by 2. Otherwise, multiply it by 3, then add 1.
  2. Loop back to step 1. Keep on repeating step 1 again and again and again...

For example, start with 10. It's even, so divide by two. That gives you 5. It's odd, so multiply it by 3 and add 1: (5 × 3) + 1 = 16. 16 is even, so take half and get 8. Half again gives you 4. Half again gets you to 2, and half again gives you 1. Since 1 is odd, multiply by 3 and add 1 to get 4. Half of 4 gives you 2, and half of that gets you back to 1. You're in a loop now and will be forever if you keep at it.

Here's another example, using 33. You may want to try it yourself to verify that you get the following: 33, 100, 50, 25, 76, 38, 19, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1, ...

A calculator might come in handy here.

Have some fun trying some more, but note that some numbers can take a while to loop back. For example, if you were to start with 27, it takes 109 steps! Other time-consuming yet small numbers are 31, 41, 47, 55, 62, 63, 71, and 73. Of course, any of these numbers multiplied by two, four, or any other power of two will also give you a long sequence.

You might wonder whether every integer will eventually loop into this 4-2-1 pattern at the end. I have personally tested this for every number up to 1,000,000 (with a computer program, of course), and every number falls into that loop. Others have tested this conjecture to much higher numbers. Naturally, checking every number doesn't satisfy mathematicians, as it will never answer the question of whether every number will eventually loop into the pattern. This is known as the Collatz conjecture, the idea that every number does. While it seems likely to be true, proving it to be either true or false is quite difficult. No-one has found a number that doesn't work, but no-one has been able to prove that every number works.

A slight variation on the above:

  1. If your number is even, divide it by 2. Otherwise, multiply it by 3, then subtract 1.
  2. Loop back to step 1. Keep on repeating step 1 again and again and again...

What effect might subtracting instead of adding 1 have? You may want to try this out before going on.

As it turns out, every number seems to settle into a loop (I've tried every number through 100,000,000, myself), but there are three different loops this time. The first loop is 2, 1, 2, 1, 2, 1, ... . The second consists of five terms before it repeats: 5, 14, 7, 20, 10, 5, ... . The third consists of 18 terms before it repeats: 17, 50, 25, 74, 37, 110, 55, 164, 82, 41, 122, 61, 182, 91, 272, 136, 68, 34, 17, 50, ... .

Here's another looping procedure somewhat similar to the previous one. This one was developed by Clifford Pickover, who calls it the Juggler Sequence. The difference between this sequence and the loop described above is that, to get the next number, you take the square root of the current number if it is even, and multiply by the square root of the current number if it is odd, and then round down to the next-lowest integer. Most sequences end . . ., 6, 2, 1. Some take a while, though. You might want to try a few numbers. Actually proving that all sequences end in 1 would probably be quite difficult. To explain why, notice that the the next number in each sequence can be found by taking the number to the power of 1.5 if the number is odd and taking it to the power of 0.5 if it is even. If you replaced 1.5 with 1.49 and 0.5 with 0.51, some very different sequences would be produced. You may want to experiment with this.

Another looping procedure is known as aliquot chains. For this procedure, start with any natural number. Find the sum of its proper divisors (also known as aliquot parts). Now take the sum, find the sum of its aliquot parts, and so on and so on.

This loop behaves in a variety of ways. For some numbers, such as 6 and 28, the sum of their aliquot parts is equal to themselves; these are known as perfect numbers. Other numbers loop back to themselves after two (for amicable numbers) or more (for sociable numbers) iterations. Many numbers reach 1 eventually (if you start with a prime number to begin with, you'll get there really quickly).

Another well-known loop is as follows:

  1. Select a four-digit number whose digits are not all the same
  2. Rearrange the digits of the number so that they form the largest number possible.
  3. Rearrange the digits of the number so that they form the smallest number possible
  4. Subtract the smaller number from the larger number
  5. Take the result of the subtraction and repeat, starting at step 2.

If you repeat the process long enough, you'll get 6,174. It isn't known why. This loop was discovered by the Indian mathematician Dattathreya Ramachandra Kaprekar in 1946. You might want to see what happens if you try numbers of different lengths.

For the next looping procedure, start with any two numbers from 0 to 9 and follow this rule: Add the two numbers and write down just the digit that is in the ones place. Here's an example: Suppose you start with 8 and 9. Adding them gives you 17. Keep just the 7, which is in the ones place. Add the last two numbers, the 9 and the 7. That gives 16; keep the 6, then you have 8-9-7-6. Keep going, adding the last two numbers in the series each time, keeping only the digit in the ones place. Do this until you get 8 and 9 again. Then the loop starts all over. The 8-9 pattern has twelve numbers in the loop before it repeats. The pattern is: 8-9-7-6-3-9-2-1-3-4-7-1-8-9.

If going around in a numerical circle appeals to you, you may have the makings of a terrific mathematician. Hang in there. But beware. If you start with the same two numbers, but in the opposite order, and follow the same rule: 9-8-7-5, and so on, it will take 60 numbers before it starts to repeat! Don't tackle that one unless you're sure you have the time. For a quickie, try 2 and 6.

Here's some questions you might want to think about:

  1. How many different possible pairs of numbers are there to start with? (It's okay to start with two numbers that are the same).
  2. Do all pairs of numbers eventually return to the starting point?
  3. What's the shortest loop you can find?
  4. Is there a pattern of odds and evens in the loop?

Here is a numerical example using words. Start with any number (in the example below, 39). Write it as a word: thirty-nine. Then continue as shown.

Start with any number 39
Write it as a word thirty-nine
Count the letters 10
Write that as a word ten
Count the letters 3
Write that as a word three
Count the letters 5
Write that as a word five
Count the letters 4
Write that as a word four
Count the letters 4

You'll get 4 forever and ever. In fact, you will always end up with 4, no matter what number you start with originally. Try a different number and see. Convince yourself with some examples, then see if you can figure out why you'll always get to four. A good starting point would be to look at how to write out big numbers. You may also want to determine what the result would be in other languages.

Loops appear in many different areas of mathematics. If you're interested in looping, you may want to check out the pages on palindromes, sociable numbers, chaos and iterative systems, fractals, and Armstrong numbers.

Sources used (see bibliography page for titles corresponding to numbers): 32, 57, .