interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / identity-matrix.wiki

74 lines · 1175 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7text sp " "
8text minus "-"
9note emit writes every byte of a to stdout; a short write is retried, an error exits 1
10fn emit a view uchar * to void
11o = ulong 0
12while lt o len a bound 4096
13k = write 1 a o sub len a o
14if le k 0
15exit 1
16end
17o = add o ulong k
18end
19end
20note emitu writes n in decimal; 20 digits hold every ulong
21fn emitu n ulong to void
22d = new uchar 20 0
23i = ulong 20
24v = n
25while true bound 20
26i = sub i 1
27put d i uchar add rem v 10 48
28v = div v 10
29if eq v 0
30break
31end
32end
33emit part d i sub 20 i
34end
35note entry (i, j) of the n x n identity is 1 on the diagonal i = j and 0 elsewhere
36fn ident n ulong to void
37for i ulong n
38for j ulong n
39if gt j 0
40emit sp
41end
42if eq i j
43emitu 1
44else
45emitu 0
46end
47end
48emit nl
49end
50end
51fn main to int
52ident 1
53emit nl
54ident 3
55emit nl
56ident 6
57ret 0
58end
59</syntaxhighlight>
60{{out}}
61<pre>
621
63
641 0 0
650 1 0
660 0 1
67
681 0 0 0 0 0
690 1 0 0 0 0
700 0 1 0 0 0
710 0 0 1 0 0
720 0 0 0 1 0
730 0 0 0 0 1
74</pre>