Last active
August 6, 2016 15:48
-
-
Save cjauvin/3a095c790ac69eaaac2baf3620f04376 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-s', help='input string, dir arrows if none') | |
parser.add_argument('-n', type=int, default=10) | |
args = parser.parse_args() | |
N = args.n | |
# 2d array of size N | |
a = [[['.'] for _ in range(N)] for _ in range(N)] | |
# transpose of a; note that updating a will update b (and vice | |
# versa) since the inner cells are references (i.e. lists of size 1) | |
b = [[a[i][j] for i in range(N)] for j in range(N)] | |
i, j, k = 0, 0, 0 | |
for m in range(N): | |
for c, _i, j0, j1, j2, _s in [ | |
(a, m, m, N - m - 1, 1, '>'), (b, N - m - 1, m, N - m - 1, 1, 'v'), | |
(a, N - m - 1, N - m - 1, m, -1, '<'), (b, m, N - m - 1, m, -1, '^') | |
]: | |
i = _i | |
for j in range(j0, j1, j2): | |
if args.s: | |
c[i][j][0] = args.s[k] | |
k = (k + 1) % len(args.s) | |
else: | |
c[i][j][0] = _s | |
print('\n'.join([''.join(s[0] for s in r) for r in a])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment