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-mv/blob/main/si/rosetta/tasks/matrix-transposition/matrix-transposition.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / si / rosetta / tasks / matrix-transposition / matrix-transposition.om` 91 lines ยท 1606 bytes Raw Blame History 1 note Rosetta Code task "Matrix transposition": https://rosettacode.org/wiki/Matrix_transposition 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text sp " " 6 text minus "-" 7 text tt "transposed:\n" 8 global ma long 15 9 global mt long 15 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 emitwi writes a signed n right-aligned in w columns (w at most 20) 37 fn emitwi n long w ulong to void 38 d = new uchar 21 32 39 i = ulong 21 40 v = n 41 if lt n 0 42 v = neg n 43 end 44 while true bound 20 45 i = sub i 1 46 put d i uchar add long 48 rem v 10 47 v = div v 10 48 if eq v 0 49 break 50 end 51 end 52 if lt n 0 53 i = sub i 1 54 put d i 45 55 end 56 if gt w sub 21 i 57 i = sub 21 w 58 end 59 emit part d i sub 21 i 60 end 61 note ma is a 3 x 5 matrix stored row by row; its transpose mt is 5 x 3, mt[j][i] = ma[i][j] 62 fn showt r ulong c ulong to void 63 for i ulong r 64 for j ulong c 65 emitwi get mt add mul i c j 4 66 end 67 emit nl 68 end 69 end 70 fn showa r ulong c ulong to void 71 for i ulong r 72 for j ulong c 73 emitwi get ma add mul i c j 4 74 end 75 emit nl 76 end 77 end 78 fn main to int 79 for i ulong 15 80 put ma i sub long mul i i 50 81 end 82 showa 3 5 83 for i ulong 3 84 for j ulong 5 85 put mt add mul j 3 i get ma add mul i 5 j 86 end 87 end 88 emit tt 89 showt 5 3 90 ret 0 91 end