cp's OEIS Frontend

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.

A359803 a(1) = 1; for n > 1, a(n) = n-1 if a(n-1) = 1, otherwise, apply the '3x+1' function to a(n-1).

Original entry on oeis.org

1, 1, 2, 1, 4, 2, 1, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, 24, 12, 6, 3, 10, 5, 16, 8, 4, 2, 1, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1, 49, 148, 74, 37, 112, 56, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8
Offset: 1

Views

Author

Wagner Martins, Jul 17 2023

Keywords

Examples

			For n = 5, the sequence so far is (1, 1, 2, 1) a(4) = 1, therefore a(5) = 5-1 = 4.
For n = 6, the sequence so far is (1, 1, 2, 1, 4), 4 is not 1, so we apply the '3x+1' function, 4 is even, so we divide it by 2, therefore a(6) = 4/2 = 2.
For n = 9, the sequence so far is (1, 1, 2, 1, 4, 2, 1, 7), 7 is not 1, so we apply the '3x+1' function, 7 is odd, so we multiply it by 3 and add 1, therefore a(9) = 3*(7)+1 = 22.
		

Crossrefs

Selected rows from A070165.
Cf. A014682.

Programs

  • Python
    def a(length):
        sequence = [1]
        while len(sequence) < length:
            last_term = sequence[-1]
            if last_term == 1:
                next_term = len(sequence)
            elif last_term % 2 == 0:
                next_term = last_term // 2
            else:
                next_term = 3 * last_term + 1
            sequence.append(next_term)
        return sequence