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 / look-and-say-sequence / look-and-say-sequence.om

70 lines · 1339 bytes Raw Blame History
1note Rosetta Code task "Look-and-say sequence": https://rosettacode.org/wiki/Look-and-say_sequence
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5note emit writes every byte of a to stdout; a short write is retried, an error exits 1
6fn emit a view uchar * to void
7o = ulong 0
8while lt o len a bound 4096
9k = write 1 a o sub len a o
10if le k 0
11exit 1
12end
13o = add o ulong k
14end
15end
16note emitu writes n in decimal; 20 digits hold every ulong
17fn emitu n ulong to void
18d = new uchar 20 0
19i = ulong 20
20v = n
21while true bound 20
22i = sub i 1
23put d i uchar add rem v 10 48
24v = div v 10
25if eq v 0
26break
27end
28end
29emit part d i sub 20 i
30end
31note emitc writes the single byte c
32fn emitc c uchar to void
33b = new uchar 1 c
34emit b
35end
36note each term reads the previous one as runs of equal digits, writing run length then digit
37note bound: the 15th term has 102 digits; 256-byte buffers hold every term here, and no run is longer than 3
38fn main to int
39a = new uchar 256 0
40b = new uchar 256 0
41put a 0 1
42n = ulong 1
43for t ulong 15
44for i ulong n
45emitc add get a i uchar 48
46end
47emit nl
48m = ulong 0
49i = ulong 0
50while lt i n bound 256
51d = get a i
52j = i
53while lt j n bound 256
54if ne get a j d
55break
56end
57j = add j 1
58end
59put b m uchar sub j i
60put b add m 1 d
61m = add m 2
62i = j
63end
64for k ulong m
65put a k get b k
66end
67n = m
68end
69ret 0
70end