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/look-and-say-sequence.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 / 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}}
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 note emit writes every byte of a to stdout; a short write is retried, an error exits 1
8 fn emit a view uchar * to void
9 o = ulong 0
10 while lt o len a bound 4096
11 k = write 1 a o sub len a o
12 if le k 0
13 exit 1
14 end
15 o = add o ulong k
16 end
17 end
18 note emitu writes n in decimal; 20 digits hold every ulong
19 fn emitu n ulong to void
20 d = new uchar 20 0
21 i = ulong 20
22 v = n
23 while true bound 20
24 i = sub i 1
25 put d i uchar add rem v 10 48
26 v = div v 10
27 if eq v 0
28 break
29 end
30 end
31 emit part d i sub 20 i
32 end
33 note emitc writes the single byte c
34 fn emitc c uchar to void
35 b = new uchar 1 c
36 emit b
37 end
38 note each term reads the previous one as runs of equal digits, writing run length then digit
39 note bound: the 15th term has 102 digits; 256-byte buffers hold every term here, and no run is longer than 3
40 fn main to int
41 a = new uchar 256 0
42 b = new uchar 256 0
43 put a 0 1
44 n = ulong 1
45 for t ulong 15
46 for i ulong n
47 emitc add get a i uchar 48
48 end
49 emit nl
50 m = ulong 0
51 i = ulong 0
52 while lt i n bound 256
53 d = get a i
54 j = i
55 while lt j n bound 256
56 if ne get a j d
57 break
58 end
59 j = add j 1
60 end
61 put b m uchar sub j i
62 put b add m 1 d
63 m = add m 2
64 i = j
65 end
66 for k ulong m
67 put a k get b k
68 end
69 n = m
70 end
71 ret 0
72 end
73
74 {{out}}
75
76 1
77 11
78 21
79 1211
80 111221
81 312211
82 `13112221`
83 `1113213211`
84 `31131211131221`
85 `13211311123113112211`
86 `11131221133112132113212221`
87 `3113112221232112111312211312113211`
88 `1321132132111213122112311311222113111221131221`
89 `11131221131211131231121113112221121321132132211331222113112211`
90 `311311222113111231131112132112311321322112111312211312111322212311322113212221`
91