Determine if a string is squeezable: Difference between revisions

Added 11l
(Added 11l)
Line 97:
{{Template:Strings}}
<br><br>
 
=={{header|11l}}==
{{trans|Java}}
 
<lang 11l>F squeeze(input, include)
V s = ‘’
L(i) 0 .< input.len
I i == 0 | input[i - 1] != input[i] | (input[i - 1] == input[i] & input[i] != include)
s ‘’= input[i]
R s
 
V testStrings = [
‘’,
‘"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 ’,
‘122333444455555666666777777788888888999999999’,
‘The better the 4-wheel drive, the further you'll be from help when ya get stuck!’,
‘headmistressship’
]
 
V testChar = [
‘ ’,
‘-’,
‘7’,
‘.’,
‘ -r’,
‘5’,
‘e’,
‘s’
]
 
L(testNum) 0 .< testStrings.len
V s = testStrings[testNum]
L(c) testChar[testNum]
V result = squeeze(s, c)
print("use: '#.'\nold: #2 <<<#.>>>\nnew: #2 <<<#.>>>\n".format(c, s.len, s, result.len, result))</lang>
 
{{out}}
<pre>
use: ' '
old: 0 <<<>>>
new: 0 <<<>>>
 
use: '-'
old: 72 <<<"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln >>>
new: 70 <<<"If I were two-faced, would I be wearing this one?" - Abraham Lincoln >>>
 
use: '7'
old: 72 <<<..1111111111111111111111111111111111111111111111111111111111111117777888>>>
new: 69 <<<..1111111111111111111111111111111111111111111111111111111111111117888>>>
 
use: '.'
old: 72 <<<I never give 'em hell, I just tell the truth, and they think it's hell. >>>
new: 72 <<<I never give 'em hell, I just tell the truth, and they think it's hell. >>>
 
use: ' '
old: 72 <<< --- Harry S Truman >>>
new: 20 <<< --- Harry S Truman >>>
 
use: '-'
old: 72 <<< --- Harry S Truman >>>
new: 70 <<< - Harry S Truman >>>
 
use: 'r'
old: 72 <<< --- Harry S Truman >>>
new: 71 <<< --- Hary S Truman >>>
 
use: '5'
old: 45 <<<122333444455555666666777777788888888999999999>>>
new: 41 <<<12233344445666666777777788888888999999999>>>
 
use: 'e'
old: 80 <<<The better the 4-wheel drive, the further you'll be from help when ya get stuck!>>>
new: 79 <<<The better the 4-whel drive, the further you'll be from help when ya get stuck!>>>
 
use: 's'
old: 16 <<<headmistressship>>>
new: 14 <<<headmistreship>>>
 
</pre>
 
=={{header|8080 Assembly}}==
Line 237 ⟶ 319:
72<<< --- Harry S Truman >>>
71<<< --- Hary S Truman >>></pre>
 
=={{header|Ada}}==
<lang Ada>with Ada.Text_IO; use Ada.Text_IO;
1,481

edits