Determine if a string is squeezable: Difference between revisions
Content deleted Content added
Not a robot (talk | contribs) Add APL |
|||
Line 206: | Line 206: | ||
</pre> |
</pre> |
||
=={{header|APL}}== |
|||
{{works with|Dyalog APL}} |
|||
<lang APL>task←{ |
|||
⍝ Squeeze a string |
|||
squeeze ← ⊢(/⍨)≠∨1,1↓⊣≠¯1⌽⊢ |
|||
⍝ Display string and length in the manner given in the task |
|||
display ← {(¯2↑⍕≢⍵),' «««',⍵,'»»»'} |
|||
⍝ Squeeze string and display output |
|||
show ← { |
|||
r← ⊂'chr: ''',⍺,'''' |
|||
r←r,⊂' in: ',display ⍵ |
|||
r←r,⊂'out: ',display ⍺ squeeze ⍵ |
|||
↑r,⊂'' |
|||
} |
|||
⍝ Strings from the task |
|||
s1←'' |
|||
s2←'"If I were two-faced, would I be wearing this one?"' |
|||
s2←s2,' --- Abraham Lincoln ' |
|||
s3←'..1111111111111111111111111111111111111111111111111' |
|||
s3←s3,'111111111111117777888' |
|||
s4←'I never give ''em hell, I just tell the truth, and t' |
|||
s4←s4,'hey think it''s hell. ' |
|||
s5←' ' |
|||
s5←s5,' --- Harry S Truman ' |
|||
⎕←' ' show s1 |
|||
⎕←'-' show s2 |
|||
⎕←'7' show s3 |
|||
⎕←'.' show s4 |
|||
{⎕←⍵ show s5}¨' -r' |
|||
}</lang> |
|||
{{out}} |
|||
<pre>chr: ' ' |
|||
in: 0 «««»»» |
|||
out: 0 «««»»» |
|||
chr: '-' |
|||
in: 72 «««"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln »»» |
|||
out: 70 «««"If I were two-faced, would I be wearing this one?" - Abraham Lincoln »»» |
|||
chr: '7' |
|||
in: 72 «««..1111111111111111111111111111111111111111111111111111111111111117777888»»» |
|||
out: 69 «««..1111111111111111111111111111111111111111111111111111111111111117888»»» |
|||
chr: '.' |
|||
in: 72 «««I never give 'em hell, I just tell the truth, and they think it's hell. »»» |
|||
out: 72 «««I never give 'em hell, I just tell the truth, and they think it's hell. »»» |
|||
chr: ' ' |
|||
in: 72 ««« --- Harry S Truman »»» |
|||
out: 20 ««« --- Harry S Truman »»» |
|||
chr: '-' |
|||
in: 72 ««« --- Harry S Truman »»» |
|||
out: 70 ««« - Harry S Truman »»» |
|||
chr: 'r' |
|||
in: 72 ««« --- Harry S Truman »»» |
|||
out: 71 ««« --- Hary S Truman »»»</pre> |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
<lang AutoHotkey>squeezable_string(str, char){ |
<lang AutoHotkey>squeezable_string(str, char){ |