Determine if a string is squeezable: Difference between revisions

(Added AutoHotkey)
Line 1,308:
old: 16 >>>headmistressship<<<
new: 14 &gt;&gt;&gt;headmistreship&lt;&lt;&lt;</pre>
 
=={{header|Lua}}==
{{trans|D}}
<lang lua>function squeezable(s, rune)
print("squeeze: `" .. rune .. "`")
print("old: <<<" .. s .. ">>>, length = " .. string.len(s))
 
local last = nil
local le = 0
io.write("new: <<<")
for c in s:gmatch"." do
if c ~= last or c ~= rune then
io.write(c)
le = le + 1
end
last = c
end
print(">>>, length = " .. le)
 
print()
end
 
function main()
squeezable("", ' ');
squeezable("\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln ", '-')
squeezable("..1111111111111111111111111111111111111111111111111111111111111117777888", '7')
squeezable("I never give 'em hell, I just tell the truth, and they think it's hell. ", '.')
local s = " --- Harry S Truman "
squeezable(s, ' ')
squeezable(s, '-')
squeezable(s, 'r')
end
 
main()</lang>
{{out}}
<pre>squeeze: ` `
old: <<<>>>, length = 0
new: <<<>>>, length = 0
 
squeeze: `-`
old: <<<"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln >>>, length = 72
new: <<<"If I were two-faced, would I be wearing this one?" - Abraham Lincoln >>>, length = 70
 
squeeze: `7`
old: <<<..1111111111111111111111111111111111111111111111111111111111111117777888>>>, length = 72
new: <<<..1111111111111111111111111111111111111111111111111111111111111117888>>>, length = 69
 
squeeze: `.`
old: <<<I never give 'em hell, I just tell the truth, and they think it's hell. >>>, length = 72
new: <<<I never give 'em hell, I just tell the truth, and they think it's hell. >>>, length = 72
 
squeeze: ` `
old: <<< --- Harry S Truman >>>, length = 72
new: <<< --- Harry S Truman >>>, length = 20
 
squeeze: `-`
old: <<< --- Harry S Truman >>>, length = 72
new: <<< - Harry S Truman >>>, length = 70
 
squeeze: `r`
old: <<< --- Harry S Truman >>>, length = 72
new: <<< --- Hary S Truman >>>, length = 71</pre>
 
=={{header|Perl}}==
1,452

edits