Determine if a string is collapsible: Difference between revisions

Added XPL0 example.
(→‎{{header|Vlang}}: Fixed emoji problem.)
(Added XPL0 example.)
Line 3,816:
original : length = 8, string = «««😍😀🙌💃😍😍😍🙌»»»
collapsed: length = 6, string = «««😍😀🙌💃😍🙌»»»
</pre>
 
=={{header|XPL0}}==
<lang XPL0>string 0;
char C, I, J, Last;
 
proc Collapse(S); \Eliminate immediately repeated characters from string
char S;
[I:= 0; J:= 0; Last:= -1;
loop [if S(I) # Last then
[C(J):= S(I);
if S(I) = 0 then quit;
J:= J+1;
];
Last:= S(I);
I:= I+1;
];
];
 
int String, K;
[String:= [
"",
"^"If I were two-faced, would I be wearing this one?^" --- Abraham Lincoln ",
"..1111111111111111111111111111111111111111111111111111111111111117777888",
"I never give 'em hell, I just tell the truth, and they think it's hell. ",
" --- Harry S Truman "];
C:= Reserve(79+1); \space for collapsed string
for K:= 0 to 4 do
[Collapse(String(K));
Text(0, "<<<"); Text(0, String(K)); Text(0, ">>> "); IntOut(0, I); CrLf(0);
Text(0, "<<<"); Text(0, C); Text(0, ">>> "); IntOut(0, J); CrLf(0);
];
]</lang>
 
{{out}}
<pre>
<<<>>> 0
<<<>>> 0
<<<"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln >>> 72
<<<"If I were two-faced, would I be wearing this one?" - Abraham Lincoln >>> 70
<<<..1111111111111111111111111111111111111111111111111111111111111117777888>>> 72
<<<.178>>> 4
<<<I never give 'em hell, I just tell the truth, and they think it's hell. >>> 72
<<<I never give 'em hel, I just tel the truth, and they think it's hel. >>> 69
<<< --- Harry S Truman >>> 72
<<< - Hary S Truman >>> 17
</pre>
 
772

edits