RosettaCodeData/Task/Determine-if-a-string-is-co.../00-TASK.txt

81 lines
3.4 KiB
Plaintext

Determine if a character string is   ''collapsible''.
And if so,   collapse the string   (by removing   ''immediately repeated''   characters).
If a character string has   ''immediately repeated''   character(s),   the repeated characters are to be
deleted (removed), &nbsp; but not the primary (1<sup>st</sup>) character(s).
An &nbsp; ''immediately repeated'' &nbsp; character is any character that is &nbsp; <u>immediately</u> &nbsp; followed by an
identical character (or characters). &nbsp; Another word choice could've been &nbsp; ''duplicated character'', &nbsp; but that
might have ruled out &nbsp; (to some readers) &nbsp; triplicated characters &nbsp; ··· &nbsp; or more.
{This Rosetta Code task was inspired by a newly introduced &nbsp; (as of around November 2019) &nbsp; '''PL/I''' &nbsp; BIF: &nbsp; '''collapse'''.}
;Examples:
In the following character string:
<big><big> The bet<u>t</u>er the 4-whe<u>e</u>l drive, the further you'l<u>l</u> be from help when ya get stuck! </big></big>
Only the 2<sup>nd</sup> &nbsp; '''t''', &nbsp; '''e''', and &nbsp; '''l''' &nbsp; are repeated characters, &nbsp; indicated
by underscores (above), &nbsp; even though they (those characters) appear elsewhere in the character string.
So, after ''collapsing'' the string, the result would be:
<big><big> The beter the 4-whel drive, the further you'l be from help when ya get stuck! </big></big>
Another example:
In the following character string:
<big><big> headmistres<u>ss</u>hip </big></big>
The "collapsed" string would be:
<big><big> headmistreship </big></big>
;Task:
Write a subroutine/function/procedure/routine··· &nbsp; to
locate &nbsp; ''repeated'' &nbsp; characters and &nbsp; ''collapse'' &nbsp; (delete) &nbsp; them from the character
string. &nbsp; The character string can be processed from either direction.
Show all output here, on this page:
:* &nbsp; the &nbsp; original string and its length
:* &nbsp; the resultant string and its length
:* &nbsp; the above strings should be "bracketed" with &nbsp; '''<<<''' &nbsp; and &nbsp; '''>>>''' &nbsp; (to delineate blanks)
;* &nbsp; «««Guillemets may be used instead for "bracketing" for the more artistic programmers, &nbsp; shown used here»»»
<!-- Guillemots shouldn't be used as they stink. !-->
Use (at least) the following five strings, &nbsp; all strings are length seventy-two (characters, including blanks), &nbsp; except
the 1<sup>st</sup> string:
string
number
╔╗
1 ║╚═══════════════════════════════════════════════════════════════════════╗ ◄■■■■■■ a null string (length zero)
2 ║"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln ║
3 ║..1111111111111111111111111111111111111111111111111111111111111117777888║
4 ║I never give 'em hell, I just tell the truth, and they think it's hell. ║
5 ║ --- Harry S Truman ║ ◄■■■■■■ has many repeated blanks
╚════════════════════════════════════════════════════════════════════════╝
{{Template:Strings}}
<br><br>