(N)
| 142 | |
| 143 | |
| 144 | def zigzag_path(N): |
| 145 | def zigzag_path_lr(N, start_row=0, start_col=0, dir_row=1, dir_col=1): |
| 146 | path = [] |
| 147 | for i in range(N): |
| 148 | for j in range(N): |
| 149 | # If the row number is even, move right; otherwise, move left |
| 150 | col = j if i % 2 == 0 else N - 1 - j |
| 151 | path.append((start_row + dir_row * i) * N + start_col + dir_col * col) |
| 152 | return path |
| 153 | |
| 154 | def zigzag_path_tb(N, start_row=0, start_col=0, dir_row=1, dir_col=1): |
| 155 | path = [] |
| 156 | for j in range(N): |
| 157 | for i in range(N): |
| 158 | # If the column number is even, move down; otherwise, move up |
| 159 | row = i if j % 2 == 0 else N - 1 - i |
| 160 | path.append((start_row + dir_row * row) * N + start_col + dir_col * j) |
| 161 | return path |
| 162 | |
| 163 | paths = [] |
| 164 | for start_row, start_col, dir_row, dir_col in [ |
| 165 | (0, 0, 1, 1), |
| 166 | (0, N - 1, 1, -1), |
| 167 | (N - 1, 0, -1, 1), |
| 168 | (N - 1, N - 1, -1, -1), |
| 169 | ]: |
| 170 | paths.append(zigzag_path_lr(N, start_row, start_col, dir_row, dir_col)) |
| 171 | paths.append(zigzag_path_tb(N, start_row, start_col, dir_row, dir_col)) |
| 172 | |
| 173 | for _index, _p in enumerate(paths): |
| 174 | paths[_index] = np.array(_p) |
| 175 | return paths |
| 176 | |
| 177 | |
| 178 | def rand_perm(N, num): |
no test coverage detected