Spiral Matrix

Правка en2, от Nickarin, 2025-10-09 03:27:35

Can someone help me find a different and right solution? I tried to do it but it gives me the wrong answer, i found a pattern and i want to share it even if its wrong

Here comes the instructions and my interpretation... - Start from the center of the matrix. - Move in a spiral: right → down → left → up → repeat. The steps of the numbers You move 1 step in the first direction, then 1 step in the second, Then 2 steps in the next direction, 2 steps in the following, Then 3 steps, 3 steps, and so on. This is the rule you were seeing: each number “occupies” two turns before increasing.

Hope someone gets to see this (sorry if its confusing english is not my native language)

Here are some examples

Example 1: matrix1 = [ [4, 4, 4, 4, 4], [4, 2, 3, 3, 3], [4, 2, 1, 1, 3], [4, 2, 2, 1, 3], [4, 4, 4, 4, 3] ]

Btw in the center you can start with 0 too

Example 2: matrix2 = [ [2, 2, 2], [2, 1, 1], [2, 2, 1] ]

I did a code but it definitely doesnt work

Теги matrix, help me, i need help

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский Nickarin 2025-10-09 03:27:35 114
en1 Английский Nickarin 2025-10-09 03:25:22 939 Initial revision (published)