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/drafts/rosettacode/determine-if-a-string-is-collapsible.wiki # 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 / drafts / rosettacode / determine-if-a-string-is-collapsible.wiki` 88 lines ยท 2369 bytes Raw Blame History 1 =={{header|Omegese}}== 2 {{works with|omc|sha256 `2c824805`, aien-dev/omega-mv `e5b32567`, Linux AArch64}} 3 Omega has no imports, so the small output helpers (emit and friends) are part of the program. 4 5 om2 6 text nl "\n" 7 text lq "<<<" 8 text rq ">>>" 9 text tlen " length " 10 text c0 "\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln " 11 text c1 "..`1111111111111111111111111111111111111111111111111111111111111117777888`" 12 text c2 "I never give 'em hell, I just tell the truth, and they think it's hell. " 13 text c3 " --- Harry S Truman " 14 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 15 fn emit a view uchar * to void 16 o = ulong 0 17 while lt o len a bound 4096 18 k = write 1 a o sub len a o 19 if le k 0 20 exit 1 21 end 22 o = add o ulong k 23 end 24 end 25 note emitu writes n in decimal; 20 digits hold every ulong 26 fn emitu n ulong to void 27 d = new uchar 20 0 28 i = ulong 20 29 v = n 30 while true bound 20 31 i = sub i 1 32 put d i uchar add rem v 10 48 33 v = div v 10 34 if eq v 0 35 break 36 end 37 end 38 emit part d i sub 20 i 39 end 40 fn line a view uchar * to void 41 emit lq 42 emit a 43 emit rq 44 emit tlen 45 emitu len a 46 emit nl 47 end 48 note collapse keeps a byte only when it differs from the byte before it 49 fn collapse a view uchar * to void 50 o = new uchar 256 0 51 n = ulong 0 52 for i ulong len a 53 c = get a i 54 k = true 55 if gt i 0 56 k = ne c get a sub i 1 57 end 58 if k 59 put o n c 60 n = add n 1 61 end 62 end 63 line a 64 line part o 0 n 65 end 66 fn main to int 67 note the empty string, as a slice of length 0 68 collapse part c0 0 0 69 collapse c0 70 collapse c1 71 collapse c2 72 collapse c3 73 ret 0 74 end 75 76 {{out}} 77

78 <<<>>> length 0

79 <<<>>> length 0

80 <<<"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln >>> length 72

81 <<<"If I were two-faced, would I be wearing this one?" - Abraham Lincoln >>> length 70

82 <<<..`1111111111111111111111111111111111111111111111111111111111111117777888`>>> length 72

83 <<<.178>>> length 4

84 <<<I never give 'em hell, I just tell the truth, and they think it's hell. >>> length 72

85 <<<I never give 'em hel, I just tel the truth, and they think it's hel. >>> length 69

86 <<< --- Harry S Truman >>> length 72

87 <<< - Hary S Truman >>> length 17

88