Determine if a string is squeezable: Difference between revisions

m (→‎{{header|REXX}}: added zkl header)
(→‎{{header|zkl}}: added code)
Line 367:
 
=={{header|zkl}}==
<lang zkl><fcn squeeze(c,str){ /lang>/ no Unicode
s,cc := Data(Void,str), String(c,c); // byte buffer in case of LOTs of deletes
<lang zkl></lang>
while(Void != (n:=s.find(cc))){ str=s.del(n) } // and searching is faster for big strings
s.text
}</lang>
<lang zkl></lang>strings:=T(
T("",""),
T("-","\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln "),
T("7","..1111111111111111111111111111111111111111111111111111111111111117777888"),
T(" ","I never give 'em hell, I just tell the truth, and they think it's hell. "),
T(" "," --- Harry S Truman "),
T("-"," --- Harry S Truman "),
T("r"," --- Harry S Truman "),
T("e","The better the 4-wheel drive, the further you'll be from help when ya get stuck!"),
T("s","headmistressship")
);
 
foreach c,s in (strings){
println("Sqeeze: \"",c,"\"");
println("Before: %3d <<<%s>>>".fmt(s.len(),s));
sstr:=squeeze(c,s);
println("After: %3d <<<%s>>>\n".fmt(sstr.len(),sstr));
}</lang>
{{out}}
<pre>
Sqeeze: ""
Before: 0 <<<>>>
After: 0 <<<>>>
 
Sqeeze: "-"
Before: 72 <<<"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln >>>
After: 70 <<<"If I were two-faced, would I be wearing this one?" - Abraham Lincoln >>>
 
Sqeeze: "7"
Before: 72 <<<..1111111111111111111111111111111111111111111111111111111111111117777888>>>
After: 69 <<<..1111111111111111111111111111111111111111111111111111111111111117888>>>
 
Sqeeze: " "
Before: 72 <<<I never give 'em hell, I just tell the truth, and they think it's hell. >>>
After: 72 <<<I never give 'em hell, I just tell the truth, and they think it's hell. >>>
 
Sqeeze: " "
Before: 72 <<< --- Harry S Truman >>>
After: 20 <<< --- Harry S Truman >>>
 
Sqeeze: "-"
Before: 72 <<< --- Harry S Truman >>>
After: 70 <<< - Harry S Truman >>>
 
Sqeeze: "r"
Before: 72 <<< --- Harry S Truman >>>
After: 71 <<< --- Hary S Truman >>>
 
Sqeeze: "e"
Before: 80 <<<The better the 4-wheel drive, the further you'll be from help when ya get stuck!>>>
After: 79 <<<The better the 4-whel drive, the further you'll be from help when ya get stuck!>>>
 
Sqeeze: "s"
Before: 16 <<<headmistressship>>>
After: 14 <<<headmistreship>>>
</pre>
Anonymous user