interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / ordered-words / ordered-words.om

57 lines · 1348 bytes Raw Blame History
1note Rosetta Code task "Ordered words": https://rosettacode.org/wiki/Ordered_words
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5note the word list (Rosetta Code reads unixdict.txt; this is a fixed sample of it), newline-terminated
6text 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"
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 ordered: every letter is at least the one before it
19fn ordered a view uchar * to bool
20for i ulong len a
21if gt i 0
22if lt get a i get a sub i 1
23ret false
24end
25end
26end
27ret true
28end
29note two passes over the list: the longest ordered length, then every ordered word of that length
30fn longest to ulong
31best = ulong 0
32s = ulong 0
33for i ulong len dict
34if eq get dict i 10
35n = sub i s
36if and ordered part dict s n gt n best
37best = n
38end
39s = add i 1
40end
41end
42ret best
43end
44fn main to int
45best = longest
46s = ulong 0
47for i ulong len dict
48if eq get dict i 10
49n = sub i s
50if and ordered part dict s n eq n best
51emit part dict s add n 1
52end
53s = add i 1
54end
55end
56ret 0
57end