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 / ordered-words.wiki

64 lines · 1491 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 the word list (Rosetta Code reads unixdict.txt; this is a fixed sample of it), newline-terminated
8text dict "almost\nabbey\naccent\nbegin\nbiopsy\nchimp\nchintz\ndeist\neffort\nfirst\nghost\nglory\nfloor\nknotty\nbillowy\nbijoux\nabhors\naegilops\nthis\nthat\nzebra\nbellow\nadder\ncello\n"
9note emit writes every byte of a to stdout; a short write is retried, an error exits 1
10fn emit a view uchar * to void
11o = ulong 0
12while lt o len a bound 4096
13k = write 1 a o sub len a o
14if le k 0
15exit 1
16end
17o = add o ulong k
18end
19end
20note ordered: every letter is at least the one before it
21fn ordered a view uchar * to bool
22for i ulong len a
23if gt i 0
24if lt get a i get a sub i 1
25ret false
26end
27end
28end
29ret true
30end
31note two passes over the list: the longest ordered length, then every ordered word of that length
32fn longest to ulong
33best = ulong 0
34s = ulong 0
35for i ulong len dict
36if eq get dict i 10
37n = sub i s
38if and ordered part dict s n gt n best
39best = n
40end
41s = add i 1
42end
43end
44ret best
45end
46fn main to int
47best = longest
48s = ulong 0
49for i ulong len dict
50if eq get dict i 10
51n = sub i s
52if and ordered part dict s n eq n best
53emit part dict s add n 1
54end
55s = add i 1
56end
57end
58ret 0
59end
60</syntaxhighlight>
61{{out}}
62<pre>
63aegilops
64</pre>