interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / si / rosetta / tasks / floyds-triangle / floyds-triangle.om

81 lines · 1485 bytes Raw Blame History
1note Rosetta Code task "Floyd's triangle": https://rosettacode.org/wiki/Floyd's_triangle
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
6text minus "-"
7note emit writes every byte of a to stdout; a short write is retried, an error exits 1
8fn emit a view uchar * to void
9o = ulong 0
10while lt o len a bound 4096
11k = write 1 a o sub len a o
12if le k 0
13exit 1
14end
15o = add o ulong k
16end
17end
18note emitu writes n in decimal; 20 digits hold every ulong
19fn emitu n ulong to void
20d = new uchar 20 0
21i = ulong 20
22v = n
23while true bound 20
24i = sub i 1
25put d i uchar add rem v 10 48
26v = div v 10
27if eq v 0
28break
29end
30end
31emit part d i sub 20 i
32end
33note emitw writes n right-aligned in w columns (w at most 20; a wider number is not cut)
34fn emitw n ulong w ulong to void
35d = new uchar 20 32
36i = ulong 20
37v = n
38while true bound 20
39i = sub i 1
40put d i uchar add rem v 10 48
41v = div v 10
42if eq v 0
43break
44end
45end
46if gt w sub 20 i
47i = sub 20 w
48end
49emit part d i sub 20 i
50end
51note row r (from 0) holds r+1 consecutive numbers; column j is as wide as the last row's entry in
52note column j, which is the widest in that column
53fn digits v ulong to ulong
54d = ulong 1
55while ge v 10 bound 20
56v = div v 10
57d = add d 1
58end
59ret d
60end
61fn floyd n ulong to void
62last = add div mul sub n 1 n 2 1
63k = ulong 1
64for r ulong n
65for j ulong add r 1
66w = digits add last j
67if gt j 0
68emit sp
69end
70emitw k w
71k = add k 1
72end
73emit nl
74end
75end
76fn main to int
77floyd 5
78emit nl
79floyd 14
80ret 0
81end