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/determine-if-a-string-is-collapsible/determine-if-a-string-is-collapsible.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 / determine-if-a-string-is-collapsible / determine-if-a-string-is-collapsible.om` 72 lines ยท 1576 bytes Raw Blame History 1 note Rosetta Code task "Determine if a string is collapsible": https://rosettacode.org/wiki/Determine_if_a_string_is_collapsible 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text lq "<<<" 6 text rq ">>>" 7 text tlen " length " 8 text c0 "\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln " 9 text c1 "..`1111111111111111111111111111111111111111111111111111111111111117777888`" 10 text c2 "I never give 'em hell, I just tell the truth, and they think it's hell. " 11 text c3 " --- Harry S Truman " 12 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 13 fn emit a view uchar * to void 14 o = ulong 0 15 while lt o len a bound 4096 16 k = write 1 a o sub len a o 17 if le k 0 18 exit 1 19 end 20 o = add o ulong k 21 end 22 end 23 note emitu writes n in decimal; 20 digits hold every ulong 24 fn emitu n ulong to void 25 d = new uchar 20 0 26 i = ulong 20 27 v = n 28 while true bound 20 29 i = sub i 1 30 put d i uchar add rem v 10 48 31 v = div v 10 32 if eq v 0 33 break 34 end 35 end 36 emit part d i sub 20 i 37 end 38 fn line a view uchar * to void 39 emit lq 40 emit a 41 emit rq 42 emit tlen 43 emitu len a 44 emit nl 45 end 46 note collapse keeps a byte only when it differs from the byte before it 47 fn collapse a view uchar * to void 48 o = new uchar 256 0 49 n = ulong 0 50 for i ulong len a 51 c = get a i 52 k = true 53 if gt i 0 54 k = ne c get a sub i 1 55 end 56 if k 57 put o n c 58 n = add n 1 59 end 60 end 61 line a 62 line part o 0 n 63 end 64 fn main to int 65 note the empty string, as a slice of length 0 66 collapse part c0 0 0 67 collapse c0 68 collapse c1 69 collapse c2 70 collapse c3 71 ret 0 72 end