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