Determine if a string is squeezable: Difference between revisions

Added XPL0 example.
(Fixed Frink)
(Added XPL0 example.)
Line 3,772:
original : length = 8, string = «««😍😀🙌💃😍😍😍🙌»»»
squeezed : length = 6, string = «««😍😀🙌💃😍🙌»»»
</pre>
 
=={{header|XPL0}}==
<lang XPL0>string 0;
char C, I, J, Last;
 
proc Squeeze(Char, S); \Eliminate specified repeated characters from string
char Char, S;
[I:= 0; J:= 0; Last:= -1;
loop [if S(I) # Last or Char # Last then
[C(J):= S(I);
if S(I) = 0 then quit;
J:= J+1;
];
Last:= S(I);
I:= I+1;
];
];
 
int String, K, Char;
[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 "];
Char:= [0, ^-, ^1, ^l, ^ , ^-, ^r];
C:= Reserve(79+1); \space for collapsed string
for K:= 0 to 4+2 do
[Squeeze(Char(K), String(if K>4 then 4 else K));
Text(0, "<<<"); Text(0, String(if K>4 then 4 else 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
<<<..17777888>>> 10
<<<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
<<< --- Harry S Truman >>> 20
<<< --- Harry S Truman >>> 72
<<< - Harry S Truman >>> 70
<<< --- Harry S Truman >>> 72
<<< --- Hary S Truman >>> 71
</pre>
 
772

edits