Sha256: d4353cbd72d084d009fbc30320385ccc15d793f82546b5fa0ba3ca09b09a0888

Contents?: true

Size: 314 Bytes

Versions: 78

Compression:

Stored size: 314 Bytes

Contents

def spiral(size):
    sm = [[0]*size for k in range(size)]
    i, j, el = 0, -1, 1
    di, dj = [0, 1, 0, -1], [1, 0, -1, 0]
    for x in range(2*size - 1):
        for y in range((2*size - x) // 2):
            i += di[x % 4]
            j += dj[x % 4]
            sm[i][j] = el
            el += 1
    return sm

Version data entries

78 entries across 78 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.138 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.137 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.136 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.135 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.134 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.133 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.132 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.131 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.130 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.129 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.128 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.127 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.126 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.125 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.124 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.123 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.122 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.121 tracks/python/exercises/spiral-matrix/example.py
trackler-2.2.1.120 tracks/python/exercises/spiral-matrix/example.py