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.

Previous Showing 11-19 of 19 results.

A333714 Squares visited by a chess king moving on a square-spiral numbered board where the king moves to the adjacent unvisited square containing the spiral number with the most divisors. In case of a tie it chooses the square with the highest spiral number.

Original entry on oeis.org

1, 8, 24, 48, 80, 120, 168, 224, 288, 360, 440, 528, 624, 728, 840, 960, 1088, 1224, 1368, 1520, 1680, 1848, 2024, 2208, 2400, 2600, 2808, 3024, 3248, 3480, 3720, 3968, 4224, 4488, 4760, 5040, 5328, 5624, 5928, 6240, 6560, 6888, 7224, 7568, 7920, 8280, 8648, 9024, 9408, 9800, 10200, 10608
Offset: 1

Views

Author

Scott R. Shannon, Jul 02 2020

Keywords

Comments

This sequence gives the numbers of the squares visited by a chess king moving on a square-spiral numbered board where the king starts on the 1 numbered square and at each step moves to an adjacent unvisited square, out of the eight adjacent neighboring squares, which contains the number with the most divisors. If two or more adjacent squares exist with the same highest number of divisors then the square with the highest spiral number is chosen. Given both of these rules tend to force the king to squares with larger numbers, and thus move away from the central 1 starting square, it is remarkable that the king is eventually trapped. Note that if the king simply moves to the highest available number the sequence will be infinite as the king will step along the southeast diagonal from square 1 forever.
The sequence is finite. After 1113 steps the square with number 855481 is visited, after which all adjacent neighboring squares have been visited.
Due to the king's preference for squares with the most divisors it will avoid prime numbers unless no other choice exists. Of the 1113 visited squares only once does it visit a square with a prime number, at a(308) = 108223. This is due to a(307) = 106913 having square 108223 as its sole neighboring unvisited square. This is the only time in the sequence where only one unvisited adjacent neighbor is available.
As even numbers >= 6 will always contain 4 or more divisors the king will tend to visit more even numbers than odd numbers; in the 1113 visited squares 929 contain an even number while only 184 contain an odd number.
As the even numbers are diagonally adjacent in the square spiral the king's path will be dominated by diagonal steps, often taking many diagonal steps in succession - see the attached link image. In fact after the first downward step to 8 the next 110 steps are along the southeast diagonal, stepping to successively larger even numbers. This sequence is finally broken on the 112th step when the square with number 50624, with 28 divisors, is the next square in the southeast direction. However the square with number 50622, with 32 divisors, is in the southwest direction so is the next square chosen. It is not until the 166th step, to the square with number 108230, that the path takes a step to a lower number than the one it is currently on.
The largest visited square is a(1050) = 942676. The visited square with the maximum number of divisors is a(680) = 388080, which has 180 divisors. The lowest unvisited square is 2.

Examples

			The board is numbered with the square spiral:
.
  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 starting square for the king.
a(2) = 8. The eight unvisited squares around a(1) the king can move to are numbered 2,3,4,5,6,7,8,9. Of these 6 and 8 both have the maximum four divisors, and of those 8 is the largest.
a(3) = 24. The seven unvisited squares around a(2) = 8 the king can move to are numbered 9,2,6,7,22,23,24. Of these 24 has eight divisors, the largest number.
a(113) = 50622. The seven unvisited squares around a(112) = 49728 the king can move to are numbered 50622, 49727, 50623, 48841, 50624, 49729, 48842. Of these 50622 has thirty-two divisors, the largest number. This is the step that breaks the sequence of 110 steps to the southeast direction starting from a(2) = 8.
a(308) = 108223. This is the first and only time a prime number is visited; a(307) = 106913 has square 108223 as the sole unvisited adjacent neighbor.
a(1114) = 855481. The two unvisited squares around a(1113) = 859184 the king can move to are numbered 862894 and 855481. Of these 855481 has eight divisors, the largest number. However square 855481 is surrounded by the eight squares with numbers 859183, 855480, 851785, 859184, 851786, 859185, 855482, 851787 all of which have been previously visited, so the king is trapped.
		

Crossrefs

Cf. A333713 (choose lowest spiral number in case of tie), A335816, A316667, A330008, A329520, A326922, A328928, A328929, A033996.

A333713 Squares visited by a chess king moving on a square-spiral numbered board where the king moves to the adjacent unvisited square containing the spiral number with the most divisors. In case of a tie it chooses the square with the lowest spiral number.

Original entry on oeis.org

1, 6, 18, 40, 70, 108, 72, 42, 20, 21, 44, 45, 75, 114, 160, 216, 280, 350, 351, 352, 432, 520, 616, 720, 832, 952, 1080, 1216, 1360, 1512, 1672, 1840, 2016, 2200, 2392, 2592, 2800, 3016, 3240, 3472, 3710, 3956, 4212, 4476, 4746, 5024, 5310, 5022, 4743, 4472, 4473, 4209, 4208, 3952, 3705
Offset: 1

Views

Author

Scott R. Shannon, Jul 02 2020

Keywords

Comments

This sequences gives the numbers of the squares visited by a chess king moving on a square-spiral numbered board where the king starts on the 1 numbered square and at each step moves to an adjacent unvisited square, out of the eight adjacent neighboring squares, which contains the number with the most divisors. If two or more adjacent squares exist with the same highest number of divisors then the square with the lowest spiral number is chosen. Note that if the king simply moves to the highest available number the sequence will be infinite as the king will step along the south-east diagonal from square 1 forever.
The sequence is finite. After 1784 steps the square with number 1478 is visited, after which all adjacent neighboring squares have been visited.
Due to the king's preference for squares with the most divisors it will avoid prime numbers unless no other choice exists. Of the 1784 visited squares only 27 contain prime numbers while 1757 contain composites. As even numbers >= 6 will always contain 4 or more divisors the king will tend to visit more even numbers than odd numbers; in the 1784 visited squares 1289 contain an even number while 495 contain an odd number. As the even numbers are diagonally adjacent in the square spiral the king's path will be dominated by diagonal steps, often taking numerous diagonal steps is succession - see the attached link image.
The largest visited square is a(390) = 17664. The lowest unvisited square is 2.

Examples

			The board is numbered with the square spiral:
.
  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 starting square for the king.
a(2) = 6. The eight unvisited squares around a(1) the king can move to are numbered 2,3,4,5,6,7,8,9. Of these 6 and 8 both have the maximum four divisors, and of those 6 is the smallest.
a(3) = 18. The seven unvisited squares around a(2) = 6 the king can move to are numbered 4,5,18,19,20,7,8. Of these 18 and 20 have the maximum six divisors, and of those 18 is the smallest.
a(603) = 821. This is the first prime number visited; a(602) = 939 has square 821 as the sole unvisited adjacent neighbor.
		

Crossrefs

Cf. A333714 (choose highest spiral number in case of tie), A335816, A316667, A330008, A329520, A326922, A328928, A328929.

A335844 Squares visited by a knight moving on a square-spiral numbered board where the knight moves to the unvisited square containing the spiral number with the fewest divisors. In case of a tie it chooses the square with the lowest spiral number.

Original entry on oeis.org

1, 10, 3, 6, 17, 4, 7, 2, 5, 8, 11, 14, 29, 86, 27, 12, 31, 94, 61, 16, 19, 22, 41, 106, 67, 18, 37, 62, 139, 98, 191, 142, 97, 34, 13, 58, 89, 178, 127, 52, 83, 26, 47, 118, 163, 76, 23, 20, 43, 70, 109, 74, 71, 44, 73, 158, 113, 214, 157, 274, 271, 212, 277, 346, 211
Offset: 1

Views

Author

Scott R. Shannon, Jun 26 2020

Keywords

Comments

This sequences gives the numbers of the squares visited by a knight moving on a square-spiral numbered board, as described in A316667, where at each step the knight goes to the neighbor one knight-leap away which contains the number with the fewest divisors. If two or more neighbors exist with the same fewest number of divisors then the square with the lowest spiral number is chosen.
The sequence is finite. After 528 steps the square with number 33 is visited, after which all neighboring squares have been visited.
Due to the knight's preference for squares with the fewest divisors the knight will leap to a prime numbered square when possible, and the lowest prime if two or more unvisited primes are within one knight-leap. Therefore this sequence matches A330008 for the first 13 terms, but on the 13th step the square with number 86 is chosen as no primes are available and 86 has only four divisors, while A330008 chooses 32, the smallest available number, but which has six divisors.
Of the 528 visited squares 198 contain prime numbers while 330 contain composites. The largest visited square is a(410) = 3656.

Examples

			The board is numbered with the square spiral:
.
  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 starting square for the knight.
a(2) = 10. The eight unvisited squares the knight can leap to from a(1) are numbered 10,12,14,16,18,20,22,24. Of these 10,14,22 have the minimum four divisors, and of those 10 is the smallest.
		

Crossrefs

A343563 Squares visited by a knight moving on a square-spiral numbered board where the knight moves to the unvisited square containing the spiral number with the smallest digit sum. In case of a tie it chooses the lowest number.

Original entry on oeis.org

1, 10, 3, 30, 11, 4, 13, 2, 5, 20, 23, 6, 21, 40, 105, 202, 103, 100, 141, 250, 315, 190, 251, 140, 61, 14, 31, 12, 15, 32, 55, 130, 91, 180, 301, 234, 127, 52, 25, 50, 121, 222, 119, 220, 117, 80, 51, 124, 231, 126, 53, 26, 9, 22, 41, 106, 203, 104, 201, 102, 143, 252, 321, 480, 323, 400, 403
Offset: 1

Views

Author

Scott R. Shannon, Apr 19 2021

Keywords

Comments

This sequences gives the numbers of the squares visited by a knight moving on a square-spiral numbered board where at each step the knight moves to the unvisited neighbor one knight-leap away which contains the number with the smallest digit sum. If two or more neighbors exist with the same digit sum then from those squares the one with the lowest number is chosen.
The sequence is finite. After 790 steps the square with number 69 is visited, after which all eight neighboring squares have been visited. The largest visit spiral number is a(626) = 6112, while there are four squares with the largest visited digit sum of 19: a(373) = 2683, a(539) = 2737, a(590) = 2944, a(594) = 2728.

Examples

			The board is numbered with the square spiral:
.
  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(2) = 10 as the eight unvisited neighbors of the square a(1) = 1 are numbered 10,12,14,16,18,20,22,24, and 10, with a digit sum of 1, has the lowest digit sum of these.
a(4) = 30 as the seven unvisited neighbors of the square a(3) = 3 square are numbered 6,8,28,30,32,34,16, and 30, with a digit sum of 3, has the lowest digit sum of these.
a(9) = 5 as two of the unvisited neighbors of the square a(8) = 2 are 5 and 23, both of which have a digit sum of 5, but 5 is chosen as it is the lower number.
		

Crossrefs

A329129 Squares visited by a knight moving on a board with squares numbered with the minimum number of steps for a knight to reach the square when starting from the origin. The knight moves to the smallest numbered unvisited square; the minimum distance from the origin is used if the square numbers are equal; the smallest spiral number ordering is used if the distances are equal.

Original entry on oeis.org

0, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 4, 3, 2, 3, 4, 3, 2, 3, 4, 3, 2, 3, 4, 3, 2, 3, 4, 3, 2, 3, 4, 3, 4, 3, 2, 3, 4, 3, 2, 3, 4, 3, 4, 3, 4, 3, 4, 3, 2, 3, 4, 3, 2, 3, 4, 3, 4, 3, 4
Offset: 0

Views

Author

Scott R. Shannon, Nov 05 2019

Keywords

Comments

This sequence numbers the squares on the board by using the minimum number of steps a knight takes to reach the square when starting from the 0-squared origin. Once the board is numbered the knight starts at the origin and at each step the knight goes to an unvisited square with the smallest number. If the knight has a choice of two or more squares with the same number it then chooses the square which is the closest to the 0-squared origin. If two or more squares are found which also have the same distance to the origin, then the square which was first drawn in a square spiral numbering is chosen, i.e., the smallest spiral-numbered square as in A316667.
The sequence is finite. After 45576 steps a square with number 60 (spiral number = 56543) is visited, after which all neighboring squares have been visited.

Examples

			The squares are numbered using the minimum number of steps a knight takes to reach the square starting from the origin:
.
  +---+---+---+---+---+---+---+---+---+
  | 4 | 3 | 2 | 3 | 2 | 3 | 2 | 3 | 4 |
  +---+---+---+---+---+---+---+---+---+
  | 3 | 2 | 3 | 2 | 3 | 2 | 3 | 2 | 3 |
  +-- +---+---+---+---+---+---+---+---+
  | 2 | 3 | 4 | 1 | 2 | 1 | 4 | 3 | 2 |
  +---+---+---+---+---+---+---+---+---+
  | 3 | 2 | 1 | 2 | 3 | 2 | 1 | 2 | 3 |
  +---+---+---+---+---+---+---+---+---+
  | 2 | 3 | 2 | 3 | 0 | 3 | 2 | 3 | 2 |
  +---+---+---+---+---+---+---+---+---+
  | 3 | 2 | 1 | 2 | 3 | 2 | 1 | 2 | 3 |
  +---+---+---+---+---+---+---+---+---+
  | 2 | 3 | 4 | 1 | 2 | 1 | 4 | 3 | 2 |
  +---+---+---+---+---+---+---+---+---+
  | 3 | 2 | 3 | 2 | 3 | 2 | 3 | 2 | 3 |
  +---+---+---+---+---+---+---+---+---+
  | 4 | 3 | 2 | 3 | 2 | 3 | 2 | 3 | 4 |
  +---+---+---+---+---+---+---+---+---+
.
If the knight has a choice of two or more squares with the same number which are also the same distance from the 0-squared origin, then the square with the minimum spiral number, as shown in A316667, is chosen.
		

Crossrefs

A338927 Locations of records in A338565.

Original entry on oeis.org

1, 4, 6, 8, 12, 24, 36, 48, 72, 96, 144, 192, 240, 288, 384, 432, 576, 864, 1152, 1440, 1728, 2304, 2880, 3456, 4320, 4608, 5184, 5760, 6912, 8640, 10368, 11520, 13824, 17280, 20736, 23040, 25920, 27648, 34560, 41472, 51840, 62208, 69120, 82944
Offset: 1

Views

Author

Robert Israel, Nov 15 2020

Keywords

Comments

The first term divisible by 3 is a(3)=6.
The first term divisible by 5 is a(13)=240.
The first term divisible by 11 is a(48)=190080.

Examples

			a(3) = 6 is in the sequence because A338565(6) = 3 is greater than A338565(n) for n < 6.
		

Crossrefs

Programs

  • Maple
    ispali:= proc(n) local L;
      L:= convert(n,base,10);
      evalb(L = ListTools:-Reverse(L))
    end proc:
    N:= 200000: # for terms <= N
    Palis:= select(ispali, {$2..N}):
    A338565:= Vector(N):
    A338565[1]:= 1:
    R:= 1: bestv:= 1:
    A[1]:= 1:
    for n from 2 to N do
      A[n]:=  add(A[n/d], d= numtheory:-divisors(n) intersect Palis);
        if A[n] > bestv then bestv:= A[n]; R:= R, n
    od:
    R;
  • Mathematica
    Block[{a, s}, a[n_] := If[n == 1, n, Sum[If[(d < n && PalindromeQ[n/d]), a[d], 0], {d, Divisors[n]}]]; s = Array[a, 10^4]; Map[FirstPosition[s, #][[1]] &, Union@ FoldList[Max, s]] ] (* Michael De Vlieger, Nov 15 2020 *)

A357046 Squares visited by a knight moving on a board covered with horizontal dominoes [m|m], m = 0, 1, 2, ... in a diamond-shaped spiral, when the knight always jumps to the unvisited square with the least number on the corresponding domino.

Original entry on oeis.org

0, 11, 14, 1, 4, 13, 10, 3, 18, 7, 2, 5, 22, 9, 28, 31, 60, 15, 32, 29, 52, 25, 8, 27, 12, 53, 26, 23, 6, 17, 34, 59, 30, 87, 126, 51, 24, 45, 20, 39, 16, 33, 58, 55, 86, 125, 50, 47, 76, 21, 40, 67, 36, 61, 94, 57, 54, 85, 176, 129, 56, 93, 138, 187, 92, 137, 96, 35, 38, 19
Offset: 0

Views

Author

M. F. Hasler, Oct 19 2022

Keywords

Comments

The sequence lists the squares visited by the knight by giving their (unique) "square spiral number", as shown, e.g., in A316328 and others. (Listing the labels m of the dominoes would obviously be ambiguous; see EXAMPLE for that sequence.)
The dominoes [m|m], m = 0, 1, 2, ... are placed in a diamond-shaped spiral,
12 12 28 28
_ 13 13 11 11 27 27 _
14 14 [2 | 2] 10 10 26 26
_ 15 15 [3 | 3] [1 | 1] [9 | 9] 25
_ 16 [4 | 4] [0 | 0] [8 | 8] 24 24
The spiral starts from the origin (where the [0|0] is placed) with one step in direction North-East (where [1|1] is placed), then one in direction North-West (=> [2|2]), then two towards South-West (=> [3|3] and [4|4]) and two towards South-East (=> [5|5] and [6|6]), then three towards North-East, etc. [We chose the counter-clockwise spiral as usual in mathematics, but one would obviously get the same sequence if the spiral of dominoes and the square spiral numbering the positions were chosen in the opposite, clockwise sense.]
The endpoints of the "straight lines" are labeled with the "quarter-squares" A002620, in particular, rightmost and leftmost dominoes of each "shell" are labeled with the odd resp. even square numbers.
The sequence ends at a(2550) where the knight is stuck at position (x, y) = (28, 4) on the domino labeled m = 964.

Examples

			The knight hops from the left 0 (= the origin) on the right 1, then on the left 2, then on the right 0, then on the left 3, then on the right 2, etc.
The list of these labels would be 0, 1, 2, 0, 3, 2, 8, 3, 4, 5, 1, 4, 6, 7, 9, 11, 12, 14, 11, 10, 24, 22, 7, 8, 10, 9, 23, 6, 5, 15, 13, 12, 27, 26, 48, 23, ...
As explained in comments, the terms a(n) correspond to the (unique) "square spiral numbers" of these locations (cf. A274641 or A174344 (upside down) or A316328).
		

Crossrefs

Cf. A316328, A326924 and A326922 (choose square closest to the origin), A328908 and A328928 (variant using taxicab distance); A328909 and A328929 (variant using sup norm).
Cf. A274641, A174344 (upside down), A268038, A274923 for the square spiral numbering and corresponding (x,y) coordinates.

Programs

  • PARI
    /* function domino([x,y]) gives the label m on the domino at (x,y); it uses the map DOM to store this label with key x + i*y. */
    DOM=Map(); {domino(x)=while(!mapisdefined(DOM, x[1]+I*x[2], &x), my(M=#DOM\2, side=sqrtint(M*4-!!M), pos=sqrtint(M)*I^(side-1)+side\/2%2*I, dir=(1+I)*I^side); for(m=M, M+side\2, mapput(DOM, pos, m); mapput(DOM, pos+1, m); pos+=dir)); x}
    {coords(n, m=sqrtint(n), k=m\/2)=if(m<=n-=4*k^2, [n-3*k, -k], n>=0, [-k, k-n], n>=-m, [-k-n, k], [k, 3*k+n])}
    {local(U=[]/* used squares */, K=vector(8, i, [(-1)^(i\2)<<(i>4), (-1)^i<<(i<5)])/* knight moves */, pos(x, y)=if(y>=abs(x), 4*y^2-y-x, -x>=abs(y), 4*x^2-x-y, -y>=abs(x), (4*y-3)*y+x, (4*x-3)*x+y), t(x, p=pos(x[1], x[2]))=if(p<=U[1]||setsearch(U, p), oo, [domino(x), p]), nxt(p, x=coords(p))=vecsort(apply(K->t(x+K), K))[1][2]); my(A=List(0)/*list of positions*/); for(n=1, oo, U=setunion(U, [A[n]]); while(#U>1&&U[2]==U[1]+1, U=U[^1]); iferr(listput(A, nxt(A[n])), E, break)); print("Index of last term: ", #A-1); A357046(n)=A[n+1];} \\ same code as A326924 except for norml2 => domino
    /* to get the sequence of labels m (cf.example): */
    [domino(coords(A357046(n))) | n <- [0..99]]

A361377 Squares visited by a knight moving on a spirally numbered board always to the lowest unvisited coprime square.

Original entry on oeis.org

1, 10, 3, 8, 5, 2, 7, 4, 9, 22, 19, 16, 33, 58, 13, 28, 25, 46, 21, 40, 17, 6, 23, 20, 39, 70, 43, 76, 47, 26, 11, 14, 29, 32, 15, 62, 37, 18, 35, 38, 63, 34, 59, 30, 53, 12, 31, 54, 85, 124, 51, 80, 83, 52, 49, 24, 77, 48, 119, 50, 27, 86, 55, 128, 89, 92
Offset: 1

Views

Author

Jodi Spitz, Mar 09 2023

Keywords

Comments

Many of these sequences (see cross-references) are finite. I've worked this out by hand, but I suspect this sequence is also finite.
The sequence is finite with 156 terms. - Rémy Sigrist, Mar 12 2023

Examples

			The spiral board begins:
   .---.---.--33--32--31
                       |
  17--16--15--14--13  30
   |               |   |
  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(9) = 9 and a(10) = 22. For a knight on square 9, the smallest unused square which is both coprime to and a knight's move away from 9 is 22.
		

Crossrefs

Programs

  • PARI
    See Links section.

Extensions

Data corrected by Rémy Sigrist, Mar 12 2023

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

Views

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.
		

Crossrefs

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])
Previous Showing 11-19 of 19 results.