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 / longest-common-subsequence.wiki

88 lines · 1965 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"
7text sp " "
8text a1 "thisisatest"
9text b1 "testing123testing"
10text a2 "1234"
11text b2 "1224533324"
12note emit writes every byte of a to stdout; a short write is retried, an error exits 1
13fn emit a view uchar * to void
14o = ulong 0
15while lt o len a bound 4096
16k = write 1 a o sub len a o
17if le k 0
18exit 1
19end
20o = add o ulong k
21end
22end
23note fill writes the (len a + 1) x (len b + 1) length table into t, row-major with width len b + 1;
24note both lengths up to 63
25fn fill a view uchar * b view uchar * t edit ulong 4096 to void
26w = add len b 1
27for i ulong len a
28for j ulong len b
29up = add mul i w add j 1
30x = add get t sub up 1 1
31if ne get a i get b j
32x = get t up
33l = get t add up sub w 1
34if lt x l
35x = l
36end
37end
38put t add up w x
39end
40end
41end
42note goup: the cell above is at least the cell to the left
43fn goup t view ulong 4096 i ulong j ulong w ulong to bool
44u = get t add mul sub i 1 w j
45ret ge u get t add mul i w sub j 1
46end
47note walk goes back from the corner of the table: a match is taken, otherwise the larger neighbour,
48note the upper one on a tie. The subsequence is written into o back to front.
49fn walk a view uchar * b view uchar * t view ulong 4096 o edit uchar 64 to void
50w = add len b 1
51i = len a
52j = len b
53k = get t add mul i w j
54while and gt i 0 gt j 0 bound 200
55if eq get a sub i 1 get b sub j 1
56k = sub k 1
57put o k get a sub i 1
58i = sub i 1
59j = sub j 1
60else
61if goup t i j w
62i = sub i 1
63else
64j = sub j 1
65end
66end
67end
68end
69fn lcs a view uchar * b view uchar * to void
70t = new ulong 4096 0
71fill a b t
72o = new uchar 64 0
73n = get t add mul len a add len b 1 len b
74walk a b t o
75emit part o 0 n
76emit nl
77end
78fn main to int
79lcs a1 b1
80lcs a2 b2
81ret 0
82end
83</syntaxhighlight>
84{{out}}
85<pre>
86tsitest
871234
88</pre>