Skip to main content
added 1 character in body
Source Link

Create a script that, given an integer \$n\$, printcreate a square matrix of dimensions \$n \times n\$ with the numbers from \$1\$ to \$n^2\$, arranged in a snail pattern.

Create a script that, given an integer \$n\$, print a square matrix of dimensions \$n \times n\$ with the numbers from \$1\$ to \$n^2\$, arranged in a snail pattern.

Create a script that, given an integer \$n\$, create a square matrix of dimensions \$n \times n\$ with the numbers from \$1\$ to \$n^2\$, arranged in a snail pattern.

LaTeXified the intro.
Source Link
coderodde
  • 32.3k
  • 15
  • 79
  • 205

Create a script that, given an integer n\$n\$, print a square matrix of n x ndimensions \$n \times n\$ with the numbers from 1\$1\$ to n²\$n^2\$, arranged in a snail pattern.

Create a script that, given an integer n, print a matrix of n x n with the numbers from 1 to n², arranged in a snail pattern.

Create a script that, given an integer \$n\$, print a square matrix of dimensions \$n \times n\$ with the numbers from \$1\$ to \$n^2\$, arranged in a snail pattern.

added 722 characters in body
Source Link

Visual representation of the matrix with code that generate the picture (I use matplotlib==3.8.4):

def show_snail(n) -> None:
    import matplotlib.pyplot as plt

    matrix = square(n)
    # Using matplotlib to create a heatmap of the matrix
    plt.figure(figsize=(8, 8))
    plt.imshow(
        matrix, cmap="viridis"
    )  # You can choose any colormap like 'viridis', 'hot', 'cool', etc.
    plt.gca().set_position(
        [0, 0, 1, 1]
    )  # Set the axes to fill the whole figure area
    plt.gcf().set_size_inches(w=1, h=1)
    plt.axis("off")  # Hide the axes
    plt.show()

show_snail(5)

spiral pattern matrix

Visual representation of the matrix with code that generate the picture (I use matplotlib==3.8.4):

def show_snail(n) -> None:
    import matplotlib.pyplot as plt

    matrix = square(n)
    # Using matplotlib to create a heatmap of the matrix
    plt.figure(figsize=(8, 8))
    plt.imshow(
        matrix, cmap="viridis"
    )  # You can choose any colormap like 'viridis', 'hot', 'cool', etc.
    plt.gca().set_position(
        [0, 0, 1, 1]
    )  # Set the axes to fill the whole figure area
    plt.gcf().set_size_inches(w=1, h=1)
    plt.axis("off")  # Hide the axes
    plt.show()

show_snail(5)

spiral pattern matrix

Became Hot Network Question
added 2 characters in body
Source Link
toolic
  • 16.4k
  • 6
  • 29
  • 221
Loading
Source Link
Loading