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/drafts/rosettacode/zig-zag-matrix.wiki
# 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 / drafts / rosettacode / zig-zag-matrix.wiki`
102 lines ยท 1878 bytes Raw Blame History
1 =={{header|Omegese}}==
2 {{works with|omc|sha256 `2c824805`, aien-dev/omega-mv `e5b32567`, Linux AArch64}}
3 Omega has no imports, so the small output helpers (emit and friends) are part of the program.
4
5 om2
6 text nl "\n"
7 text sp " "
8 text minus "-"
9 global grid ulong 64
10 note emit writes every byte of a to stdout; a short write is retried, an error exits 1
11 fn emit a view uchar * to void
12 o = ulong 0
13 while lt o len a bound 4096
14 k = write 1 a o sub len a o
15 if le k 0
16 exit 1
17 end
18 o = add o ulong k
19 end
20 end
21 note emitu writes n in decimal; 20 digits hold every ulong
22 fn emitu n ulong to void
23 d = new uchar 20 0
24 i = ulong 20
25 v = n
26 while true bound 20
27 i = sub i 1
28 put d i uchar add rem v 10 48
29 v = div v 10
30 if eq v 0
31 break
32 end
33 end
34 emit part d i sub 20 i
35 end
36 note emitw writes n right-aligned in w columns (w at most 20; a wider number is not cut)
37 fn emitw n ulong w ulong to void
38 d = new uchar 20 32
39 i = ulong 20
40 v = n
41 while true bound 20
42 i = sub i 1
43 put d i uchar add rem v 10 48
44 v = div v 10
45 if eq v 0
46 break
47 end
48 end
49 if gt w sub 20 i
50 i = sub 20 w
51 end
52 emit part d i sub 20 i
53 end
54 note number the cells along the anti-diagonals d = i + j; even diagonals run up and to the right
55 note (i falling), odd ones down and to the left (i rising)
56 fn zigzag n ulong to void
57 k = ulong 0
58 for d ulong sub mul n 2 1
59 for x ulong add d 1
60 i = x
61 if eq rem d 2 0
62 i = sub d x
63 end
64 if and lt i n le sub d i sub n 1
65 put grid add mul i n sub d i k
66 k = add k 1
67 end
68 end
69 end
70 end
71 fn show n ulong to void
72 for i ulong n
73 for j ulong n
74 emitw get grid add mul i n j 3
75 end
76 emit nl
77 end
78 end
79 fn main to int
80 zigzag 5
81 show 5
82 emit nl
83 zigzag 6
84 show 6
85 ret 0
86 end
87
88 {{out}}
89
90 0 1 5 6 14
91 2 4 7 13 15
92 3 8 12 16 21
93 9 11 17 20 22
94 10 18 19 23 24
95
96 0 1 5 6 14 15
97 2 4 7 13 16 25
98 3 8 12 17 24 26
99 9 11 18 23 27 32
100 10 19 22 28 31 33
101 20 21 29 30 34 35
102