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

91 lines · 1791 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"
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 emitc writes the single byte c
34fn emitc c uchar to void
35b = new uchar 1 c
36emit b
37end
38note each term reads the previous one as runs of equal digits, writing run length then digit
39note bound: the 15th term has 102 digits; 256-byte buffers hold every term here, and no run is longer than 3
40fn main to int
41a = new uchar 256 0
42b = new uchar 256 0
43put a 0 1
44n = ulong 1
45for t ulong 15
46for i ulong n
47emitc add get a i uchar 48
48end
49emit nl
50m = ulong 0
51i = ulong 0
52while lt i n bound 256
53d = get a i
54j = i
55while lt j n bound 256
56if ne get a j d
57break
58end
59j = add j 1
60end
61put b m uchar sub j i
62put b add m 1 d
63m = add m 2
64i = j
65end
66for k ulong m
67put a k get b k
68end
69n = m
70end
71ret 0
72end
73</syntaxhighlight>
74{{out}}
75<pre>
761
7711
7821
791211
80111221
81312211
8213112221
831113213211
8431131211131221
8513211311123113112211
8611131221133112132113212221
873113112221232112111312211312113211
881321132132111213122112311311222113111221131221
8911131221131211131231121113112221121321132132211331222113112211
90311311222113111231131112132112311321322112111312211312111322212311322113212221
91</pre>