Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/tasks/zig-zag-matrix/oracle.py # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / tasks / zig-zag-matrix / oracle.py` 15 lines ยท 629 bytes Raw Blame History 1 # Independent reference for "Zig-zag matrix" (Python 3, standard library only). 2 # expected.txt is this program's stdout; omc never produced it. 3 # sort the cells by (diagonal, position along it in the direction of travel) 4 def zigzag(n): 5 cells = sorted(((i, j) for i in range(n) for j in range(n)), 6 key=lambda p: (p[0] + p[1], -p[0] if (p[0] + p[1]) % 2 == 0 else p[0])) 7 m = [[0] * n for _ in range(n)] 8 for k, (i, j) in enumerate(cells): 9 m[i][j] = k 10 return m 11 for t, n in enumerate((5, 6)): 12 if t: 13 print() 14 for row in zigzag(n): 15 print("".join(f"{v:3}" for v in row))