This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A232462 #29 Oct 03 2024 15:13:53 %S A232462 0,1,4,2,3,0,6,5,8,4,5,7,7,8,8,3,9,9,9,1,1,6,6,6,4,6,7,8,8,8,11,4,10, %T A232462 5,5,9,9,9,7,7,7,7,2,8,8,8,11,9,10,10,10,9,9,12,12,9,7,9,7,9,9,7,7,1, %U A232462 10,10,10,6,6,6,11,4,0,4,6,4,4,7,7,6,4,7,7,6,6,2,2,8,2,8,8,8,8,11,11,5,7,10,10,10,10,10,10,5,7,5,2,5,5,5,9,9,5,7,7,9,9,7,7,9 %N A232462 Number of iterations of the map n -> f(f(f(...f(n)...))) to reach the end of the cycle, where f(n) = A006666(n), the initial number n is not counted. %C A232462 The 3x+1 or Collatz problem is as follows: start with any number n. If n is even, divide it by 2, otherwise multiply it by 3 and add 1. As multiplying by 3 and adding 1 always gives an even number, the next step is always a division by 2. So there already exists a shortened version of Collatz problem: If n is even, multiply it by three, add one and divide the result by two, else divide it by two. A006666(n), which is the Number of halving steps to reach 1 in '3x+1' problem, also is the number of all steps for the shortened form to reach 1. If you map this function onto itself, you'll get a sequence that ends with 1 or 6 (for 6, 20, 21, 43, 64, 86, ...) or 73 (for 73, 216, 218, ...). %H A232462 Christoph Neubauer, <a href="/A232462/b232462.txt">Table of n, a(n) for n = 1..10000</a> %e A232462 For n = 3, the mapping of the shortened Collatz sequence is [3, 5, 4, 2, 1], its number of steps is 4. For n=6 the sequence is [6], the number of steps is 0. %o A232462 (Python) %o A232462 #!/usr/bin/env python %o A232462 # output to %o A232462 outputStr = "b232462.txt" %o A232462 # max index %o A232462 maxIndex = 10000 %o A232462 # goodies %o A232462 sep=" " %o A232462 eol="\n" %o A232462 # subroutine for collatz sequence; classical and shortened %o A232462 def collatz (n, k): %o A232462 # put starting number to list %o A232462 list = [n] %o A232462 # collatz assumption used as end criterion %o A232462 while (n > 1): %o A232462 # collatz formula %o A232462 if (n%2 == 0): %o A232462 n = n // 2 %o A232462 else: %o A232462 n = (3*n + 1) // k # if k==2 --> shortened %o A232462 # put new number to list %o A232462 list.append(n); %o A232462 # return complete list %o A232462 return list %o A232462 # subroutine for collatz composition; classical and shortened %o A232462 # composition: collatz (collatz (collatz (...))) %o A232462 def composition (n, k): %o A232462 # put starting number to list %o A232462 list = [n] %o A232462 # calculate collatz(starting number) %o A232462 l = len (collatz(n, k))-1 %o A232462 # while we do not have a cycle %o A232462 while ((l >= 1) and (not l in list)): %o A232462 # put new number to list %o A232462 list.append(l) %o A232462 # get next collatz number %o A232462 l = len (collatz(l, k))-1 %o A232462 # return complete list %o A232462 return list %o A232462 # open output %o A232462 output = open (outputStr, 'w') %o A232462 # for index 1 to maxIndex %o A232462 for i in range (1, maxIndex+1): %o A232462 # compute complete composition sequence %o A232462 list = composition(i, 2) %o A232462 # get number of steps %o A232462 l = len(list)-1 %o A232462 # write to file %o A232462 output.write (str(i)+sep+str(l)+eol) %o A232462 # close output %o A232462 output.close () %K A232462 nonn %O A232462 1,3 %A A232462 _Christoph Neubauer_, Nov 24 2013