0
How can I write a program that take a n(a positive number)as input,make n×n list then return the 0 and 1 into spiral.
3 Respostas
+ 2
Your attempt ?
EDIT (her answer):
Yes
This is my code but it isn't compelete
n=int(input("enter a n"))
L=[]
for i in range(n):
L.append([0]*n)
for row in L:
for i in range(n):
L[0][i]=1
L[n_1][i]=1
L[i][n_1]=1
L[i][0]=1
L[1][0]=0
+ 2
fatemeh salmani I used almot the same method. You have to find a way to get all the indexes that will be changed to 1. Here is a hint:
This how it iterates:
1) [0, 0] -> [0, n-1] -> [n-1, n-1] -> [n-1, 0] -> [2, 0], then add [2, 1]
2) [2, 2] -> [2, n-1-2] -> [n-1-2, n-1-2] -> [n-1-2, 2] -> [4, 2], then add [2, 1]
3) [4, 4] -> [4, n-1-4] -> [n-1-4, n-1-4] -> [n-1-4, 4] -> [6, 5], then add [6, 5]
Try to find the pattern
+ 2
fatemeh salmani I wrote a working script, but it is using generators and functions.
I think it is overcomplicated, there must be an easier way to do it.
I'll try to find another solution, or wait for someone to share his own solution.
NOTE:
For people who don't know what the output should be like, try my code to get an idea. (contact me for the link)