RosettaCodeData/Task/Determine-if-a-string-is-squeezable/XPL0/determine-if-a-string-is-squeezable.xpl0
2023-07-01 13:44:08 -04:00

32 lines
1 KiB
Text

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);
];
]