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.

User: Wagner Martins

Wagner Martins's wiki page.

Wagner Martins has authored 3 sequences.

A364247 Squares visited by the chess king on a spiral-numbered board, where the king moves to the square with the fewest steps to reach 1 using the 3x+1 function. In case of a tie, the king moves to the square with the smallest number.

Original entry on oeis.org

1, 2, 4, 16, 5, 6, 8, 24, 10, 26, 48, 80, 120, 168, 122, 170, 226, 227, 228, 172, 173, 174, 232, 176, 128, 88, 56, 90, 92, 136, 93, 58, 32, 13, 3, 12, 11, 28, 52, 84, 85, 53, 29, 30, 31, 57, 89, 130, 180, 181, 131, 132, 133, 184, 244, 186, 245, 312, 246, 314
Offset: 1

Author

Wagner Martins, Jul 15 2023

Keywords

Comments

The king moves to the square with the fewest steps to reach 1 using the 3x+1 function. The function works as follows: start with the number, and if it is even, divide it by 2. Otherwise, multiply it by 3 and add 1, and repeat the process until you reach 1. If there are two squares with the same number of steps, the king picks the square with the smaller number.
The sequence contains 511 terms; the king gets stuck because all the adjacent squares are already taken.
The last square visited is numbered a(511) = 6619.
The highest-numbered square reached is a(327) = 12853.

Examples

			The spiral board:
  17--16--15--14--13   .
   |               |   .
  18   5---4---3  12  29
   |   |       |   |   |
  19   6   1---2  11  28
   |   |           |   |
  20   7---8---9--10  27
   |                   |
  21--22--23--24--25--26
a(1) = 1, the initial square.
a(2) = 2 because 2 has the fewest steps to reach 1 applying the function {n/2 if n is even, 3n + 1 if n is odd} repeatedly.
		

Programs

  • Python
    class Spiral:
        def _init_(self):
            self.spiral = [[1]]
        def increment(self, increment_size):
            if increment_size == 0:  # Recursion stop condition
                return
            size = len(self.spiral)
            count = size ** 2 + 1
            if size % 2 != 0:
                self.spiral.insert(0, [])
                for i in reversed(range(0, size + 1)):
                    self.spiral[i].append(count)
                    count += 1
                for _ in range(size):
                    self.spiral[0].insert(0, count)
                    count += 1
            else:
                self.spiral.append([])
                for i in range(0, size + 1):
                    self.spiral[i].insert(0, count)
                    count += 1
                for _ in range(size):
                    self.spiral[-1].append(count)
                    count += 1
            self.increment(increment_size - 1)
        def find_position(self, target):
            for i, row in enumerate(self.spiral):
                for j, element in enumerate(row):
                    if element == target:
                        return (i, j)
        def find_king_neighbours(self, target):
            i, j = self.find_position(target)
            neighbours_position = (
                (i - 1, j - 1), (i - 1, j), (i - 1, j + 1),
                (i, j - 1), (i, j + 1),
                (i + 1, j - 1), (i + 1, j), (i + 1, j + 1)
            )
            return [self.spiral[i][j] for i, j in neighbours_position]
    def steps(x):
        count = 0
        while x != 1:
            if x % 2 == 0:
                x //= 2
            else:
                x = 3 * x + 1
            count += 1
        return count
    def min_steps(lst):
        """Find the value with the minimal amount of steps with the 3x+1 function (the smallest in case of tie)"""
        if len(lst) == 0:
            raise ValueError("Empty list")
        min_steps_seen, min_seed = float("inf"), float("inf")
        for n in lst:
            step = steps(n)
            if step < min_steps_seen or step == min_steps_seen and n < min_seed:
                min_steps_seen = step
                min_seed = n
        return min_seed
    spiral = Spiral()
    sequence = [1]
    count = 1
    print(count, 1)
    while True:
        count += 1
        spiral.increment(2)
        neighbours = spiral.find_king_neighbours(sequence[-1])
        neighbours = [n for n in neighbours if n not in sequence]
        try:
            next_square = min_steps(neighbours)
        except ValueError:
            print("End of the sequence.")
            break
        sequence.append(next_square)
        print(count, sequence[-1])

A364090 Add each term m of the sequence to the last one m times starting with 1, 1.

Original entry on oeis.org

1, 1, 2, 3, 5, 7, 10, 13, 16, 21, 26, 31, 36, 41, 48, 55, 62, 69, 76, 83, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 203, 216, 229, 242, 255, 268, 281, 294, 307, 320, 333, 346, 359, 375, 391, 407, 423, 439, 455, 471, 487, 503, 519, 535, 551, 567
Offset: 1

Author

Wagner Martins, Jul 09 2023

Keywords

Comments

a(n) seems to grow as n^c where c is a constant with the value of approximately 1.625, in other words, lim_{n->oo} log_n(a(n)) seems to converge.

Examples

			k denotes the k-th iteration
The sequence is initialized with (1, 1)
For k = 1
Add a(1) = 1 once, you get (1, 1, 2)
For k = 2
Add a(2) = 1 once, you get (1, 1, 2, 3)
For k = 3
Add a(3) = 2 twice, you get (1, 1, 2, 3, 5, 7)
For k = 4
add a(4) = 3 three times, and you get (1, 1, 2, 3, 5, 7, 10, 13, 16)
		

Crossrefs

Cf. A100143.

Programs

  • Python
    def a_list(n):
        if n <= 2:
            return 1
        sequence = [1, 1]
        target_number_index = 0
        times_to_add = sequence[target_number_index]
        for _ in range(n - 2):
            if times_to_add == 0:
                target_number_index += 1
                times_to_add = sequence[target_number_index]
            last_term = sequence[-1]
            sequence.append(last_term + sequence[target_number_index])
            times_to_add -= 1
        return sequence

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

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