#๐Ÿ”’ not getting desired output

16 messages ยท Page 1 of 1 (latest)

dire linden
#

the output i am getting is
[1, 1, 1, 1, 1]
[1, 1, 1, 1, 1]
[1, 1, 1, 1, 1]
[1, 1, 1, 1, 1]
[1, 1, 1, 1, 1]

ripe cipherBOT
#

@dire linden

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

dire linden
#
def call_of_ones(n):
    matrix = [[0] * n for _ in range(n)]

    def fill_layer(layer, value=1):
        for i in range(layer, n - layer):
            matrix[layer][i] = value
        for i in range(layer + 1, n - layer):
            matrix[i][n - layer - 1] = value
        for i in range(n - layer - 2, layer - 1, -1):
            matrix[n - layer - 1][i] = value
        for i in range(n - layer - 2, layer, -1):
            matrix[i][layer] = value

    layers = (n + 1) // 2
    for layer in range(layers):
        fill_layer(layer)

    return matrix

n = 5
result = call_of_ones(n)
for row in result:
    print(row)
#

this is my question
Consider an n*n matrix of the following form:
[1 1 1 1 1]
[1 0 0 0 0]
[1 0 1 1 0]
[1 0 0 1 0]
[1 1 1 1 0]
Write a function call_of_ones(n) that produces a n x n matrix of the given form. Make sure that the recursive steps are in the correct order (i.e, the ones go right, then down, then left, then up, then right, etc.)

#

Uh anyone help?

dire linden
#

๐Ÿ˜”

balmy relic
dire linden
#

๐Ÿ˜ญ

balmy relic
balmy relic
# dire linden Ya I need help

define the function move(matrix, i, j, direction, steps, max_steps)

  • i, j is where you're at (matrix[i][j])
  • direction is the direction of the last move
  • steps is how many steps you've taken in the same direction already
  • max_steps is how many steps you should take before turning again
    go from there
dire linden
#

Umm

ripe cipherBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.