Determine if a string is collapsible: Difference between revisions

Add BASIC
(Add APL)
(Add BASIC)
Line 461:
<<<headmistressship>>> - length: 16
<<<headmistreship>>> - length: 14</pre>
 
=={{header|BASIC}}==
 
<lang basic>10 READ N%
20 FOR A% = 1 TO N%
30 READ I$: GOSUB 100
40 PRINT LEN(I$); "<<<"; I$; ">>>"
50 PRINT LEN(O$); "<<<"; O$; ">>>"
55 PRINT
60 NEXT
70 END
100 REM Collapse I$ into O$
105 IF I$="" THEN O$=I$: RETURN
110 O$=SPACE$(LEN(I$))
120 P$=LEFT$(I$,1)
130 MID$(O$,1,1)=P$
140 O%=2
150 FOR I%=2 TO LEN(I$)
160 C$=MID$(I$,I%,1)
170 IF P$<>C$ THEN MID$(O$,O%,1)=C$: O%=O%+1: P$=C$
180 NEXT
190 O$=LEFT$(O$,O%-1)
200 RETURN
400 DATA 5: REM There are 5 strings
410 DATA ""
420 DATA "'If I were two-faced, would I be wearing this one?' --- Abraham Lincoln "
430 DATA "..1111111111111111111111111111111111111111111111111111111111111117777888"
440 DATA "I never give 'em hell, I just tell the truth, and they think it's hell. "
450 DATA " --- Harry S Truman "</lang>
 
{{out}}
 
<pre> 0 <<<>>>
0 <<<>>>
 
72 <<<'If I were two-faced, would I be wearing this one?' --- Abraham Lincoln>>>
70 <<<'If I were two-faced, would I be wearing this one?' - Abraham Lincoln >>>
 
72 <<<..1111111111111111111111111111111111111111111111111111111111111117777888>>>
4 <<<.178>>>
 
72 <<<I never give 'em hell, I just tell the truth, and they think it's hell.>>>
69 <<<I never give 'em hel, I just tel the truth, and they think it's hel. >>>
 
72 <<< --- Harry S Truman>>>
17 <<< - Hary S Truman >>>
</pre>
 
=={{header|C}}==
2,124

edits