RosettaCodeData/Task/Determine-if-a-string-is-sq.../EMal/determine-if-a-string-is-sq...

33 lines
1.2 KiB
Plaintext

fun squeeze ← text by text input, text include
text sb
for int i ← 0 ; i < input.length ; ++i
if i æ 0 or input[i - 1] ≠ input[i] or (input[i - 1] æ input[i] and input[i] ≠ include)
sb.append(input[i])
end
end
return sb
end
fun main ← int by List args
List strings ← text["",
"\"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"]
List chars ← text[" ", "-", "7", ".", " -r", "5", "e", "s"]
for int i ← 0; i < strings.length ; ++i
text s ← strings[i]
for each text c in chars[i]
text result ← squeeze(s, c)
writeLine("use: '", c, "'")
writeLine("old: ", s.length, " <<<", s, ">>>")
writeLine("new: ", result.length, " <<<", result, ">>>")
writeLine()
end
end
return 0
end
exit(main(Runtime.args))