RosettaCodeData/Task/Determine-if-a-string-is-squeezable/00-TASK.txt
2023-07-01 13:44:08 -04:00

97 lines
5 KiB
Text

Determine if a character string is   ''squeezable''.
And if so,   squeeze the string   (by removing any number of
a   ''specified''   ''immediately repeated''   character).
This task is very similar to the task     '''Determine if a character string is collapsible'''     except
that only a specified character is   ''squeezed''   instead of any character that is ''immediately repeated''.
If a character string has a specified   ''immediately repeated''   character(s),   the repeated characters are to be
deleted (removed), &nbsp; but not the primary (1<sup>st</sup>) character(s).
A specified &nbsp; ''immediately repeated'' &nbsp; character is any specified 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; '''squeeze'''.}
;Examples:
In the following character string with a specified &nbsp; ''immediately repeated'' &nbsp; character of &nbsp; '''e''':
<big><big> The better the 4-whe<u>e</u>l drive, the further you'll be from help when ya get stuck! </big></big>
Only the 2<sup>nd</sup> &nbsp; '''e''' &nbsp; is an specified repeated character, &nbsp; indicated by an underscore
(above), &nbsp; even though they (the characters) appear elsewhere in the character string.
So, after ''squeezing'' the string, the result would be:
<big><big> The better the 4-whel drive, the further you'll be from help when ya get stuck! </big></big>
Another example:
In the following character string, &nbsp; using a specified immediately repeated character &nbsp; '''s''':
<big><big> headmistres<u>ss</u>hip </big></big>
The "squeezed" string would be:
<big><big> headmistreship </big></big>
;Task:
Write a subroutine/function/procedure/routine··· &nbsp; to locate a &nbsp; ''specified immediately repeated'' &nbsp; character
and &nbsp; ''squeeze'' &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; specified repeated character &nbsp; (to be searched for and possibly ''squeezed''):
:* &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:
immediately
string repeated
number character
( ↓ a blank, a minus, a seven, a period)
╔╗
1 ║╚═══════════════════════════════════════════════════════════════════════╗ ' ' ◄■■■■■■ a null string (length zero)
2 ║"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln ║ '-'
3 ║..1111111111111111111111111111111111111111111111111111111111111117777888║ '7'
4 ║I never give 'em hell, I just tell the truth, and they think it's hell. ║ '.'
5 ║ --- Harry S Truman ║ (below) ◄■■■■■■ has many repeated blanks
╚════════════════════════════════════════════════════════════════════════╝ ↑
For the 5<sup>th</sup> string (Truman's signature line), use each of these specified immediately repeated characters:
&bull; a blank
&bull; a minus
&bull; a lowercase '''r'''
Note: &nbsp; there should be seven results shown, &nbsp; one each for the 1<sup>st</sup> four strings, &nbsp; and three results for
the 5<sup>th</sup> string.
{{Template:Strings}}
<br><br>