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 / floyds-triangle.wiki

107 lines · 1995 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 emitw writes n right-aligned in w columns (w at most 20; a wider number is not cut)
36fn emitw n ulong w ulong to void
37d = new uchar 20 32
38i = ulong 20
39v = n
40while true bound 20
41i = sub i 1
42put d i uchar add rem v 10 48
43v = div v 10
44if eq v 0
45break
46end
47end
48if gt w sub 20 i
49i = sub 20 w
50end
51emit part d i sub 20 i
52end
53note row r (from 0) holds r+1 consecutive numbers; column j is as wide as the last row's entry in
54note column j, which is the widest in that column
55fn digits v ulong to ulong
56d = ulong 1
57while ge v 10 bound 20
58v = div v 10
59d = add d 1
60end
61ret d
62end
63fn floyd n ulong to void
64last = add div mul sub n 1 n 2 1
65k = ulong 1
66for r ulong n
67for j ulong add r 1
68w = digits add last j
69if gt j 0
70emit sp
71end
72emitw k w
73k = add k 1
74end
75emit nl
76end
77end
78fn main to int
79floyd 5
80emit nl
81floyd 14
82ret 0
83end
84</syntaxhighlight>
85{{out}}
86<pre>
87 1
88 2 3
89 4 5 6
90 7 8 9 10
9111 12 13 14 15
92
93 1
94 2 3
95 4 5 6
96 7 8 9 10
9711 12 13 14 15
9816 17 18 19 20 21
9922 23 24 25 26 27 28
10029 30 31 32 33 34 35 36
10137 38 39 40 41 42 43 44 45
10246 47 48 49 50 51 52 53 54 55
10356 57 58 59 60 61 62 63 64 65 66
10467 68 69 70 71 72 73 74 75 76 77 78
10579 80 81 82 83 84 85 86 87 88 89 90 91
10692 93 94 95 96 97 98 99 100 101 102 103 104 105
107</pre>