Skip to main content
fixed formatting
Source Link
Samwise
  • 4k
  • 7
  • 14

Your inside for loop is useless as it loops over 4 values ([1,2,3,4]) and you have 4 if insinde it. you could have:

N = 100
arr = [(0, 0)]

for u in range(1, N):
    # first corner
    arr.append((u, - u + 1))
    # second corner
    arr.append((u, u))
    # third corner
    arr.append((-u, u))
    # fourth corner
    arr.append((-u, -u))

# Transforms [(x1, y1), (x2, y2)...] in x = (x1, x2...) y = (y1, y2...)
x, y = zip(*arr)
plt.plot(x, y)
```

Your inside for loop is useless as it loops over 4 values ([1,2,3,4]) and you have 4 if insinde it. you could have:

N = 100
arr = [(0, 0)]

for u in range(1, N):
    # first corner
    arr.append((u, - u + 1))
    # second corner
    arr.append((u, u))
    # third corner
    arr.append((-u, u))
    # fourth corner
    arr.append((-u, -u))

# Transforms [(x1, y1), (x2, y2)...] in x = (x1, x2...) y = (y1, y2...)
x, y = zip(*arr)
plt.plot(x, y)
```

Your inside for loop is useless as it loops over 4 values ([1,2,3,4]) and you have 4 if insinde it. you could have:

N = 100
arr = [(0, 0)]

for u in range(1, N):
    # first corner
    arr.append((u, - u + 1))
    # second corner
    arr.append((u, u))
    # third corner
    arr.append((-u, u))
    # fourth corner
    arr.append((-u, -u))

# Transforms [(x1, y1), (x2, y2)...] in x = (x1, x2...) y = (y1, y2...)
x, y = zip(*arr)
plt.plot(x, y)
Source Link
Cal
  • 296
  • 1
  • 2

Your inside for loop is useless as it loops over 4 values ([1,2,3,4]) and you have 4 if insinde it. you could have:

N = 100
arr = [(0, 0)]

for u in range(1, N):
    # first corner
    arr.append((u, - u + 1))
    # second corner
    arr.append((u, u))
    # third corner
    arr.append((-u, u))
    # fourth corner
    arr.append((-u, -u))

# Transforms [(x1, y1), (x2, y2)...] in x = (x1, x2...) y = (y1, y2...)
x, y = zip(*arr)
plt.plot(x, y)
```