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