Determine if a string is collapsible: Difference between revisions

Added solution for Action!
(Add Modula-2)
(Added solution for Action!)
Line 254:
<<< --- Harry S Truman >>> 72
<<< - Hary S Truman >>> 17
</pre>
 
=={{header|Action!}}==
<lang Action!>PROC Collapse(CHAR ARRAY in,out)
BYTE i,j
CHAR c
 
j=1 c=0
FOR i=1 TO in(0)
DO
IF in(i)#c THEN
c=in(i)
out(j)=c
j==+1
FI
OD
out(0)=j-1
RETURN
 
PROC Test(CHAR ARRAY s)
CHAR ARRAY c(100)
BYTE CH=$02FC ;Internal hardware value for last key pressed
 
Collapse(s,c)
PrintF("<<<%S>>> (len=%B)%E",s,s(0))
PrintF("<<<%S>>> (len=%B)%E",c,c(0))
PutE()
PrintE("Press any key to continue")
PutE()
 
DO UNTIL CH#$FF OD
CH=$FF
RETURN
 
PROC Main()
Test("")
Test("""If I were two-faced, would I be wearing this one?"" --- Abraham Lincoln ")
Test("..1111111111111111111111111111111111111111111111111111111111111117777888")
Test("I never give 'em hell, I just tell the truth, and they think it's hell. ")
Test(" --- Harry S Truman ")
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Determine_if_a_string_is_collapsible.png Screenshot from Atari 8-bit computer]
<pre>
<<<>>> (len=0)
<<<>>> (len=0)
 
<<<"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln >>> (len=72)
<<<"If I were two-faced, would I be wearing this one?" - Abraham Lincoln >>> (len=70)
 
<<<..1111111111111111111111111111111111111111111111111111111111111117777888>>> (len=72)
<<<.178>>> (len=4)
 
<<<I never give 'em hell, I just tell the truth, and they think it's hell. >>> (len=72)
<<<I never give 'em hel, I just tel the truth, and they think it's hel. >>> (len=69)
 
<<< --- Harry S Truman >>> (len=72)
<<< - Hary S Truman >>> (len=17)
</pre>
 
Anonymous user