Jump to content

Determine if a string is squeezable: Difference between revisions

Added GNU APL equivalent
m (→‎{{header|Phix}}: added syntax colouring, marked p2js compatible)
(Added GNU APL equivalent)
Line 534:
⎕←'7' show s3
⎕←'.' show s4
{⎕←⍵ show s5}¨' -r' ⍝⍝ note use of 'show' here in a lambda (dfn)
}</lang>
{{works with|GNU APL}}
<lang APL>
#!/usr/local/bin/apl --script
 
∇r ← c squeeze s
r ← ¯1↓∊((~(s=c))⊂s),¨c
 
∇r ← display s
r ← (¯2↑⍕≢s),' «««',s,'»»»'
 
∇r ← c show s
"chr: '",c,"'"
" in: ",display s
"out: ",display c squeeze s
⍝⍝ NOTE: in GNU APL, a tradfn which may be called in a lambda
⍝⍝ MUST have a return value.
r ← ⍬
 
∇main
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 APL>
 
{{out}}
<pre>chr: ' '
Line 564 ⟶ 605:
in: 72 ««« --- Harry S Truman »»»
out: 71 ««« --- Hary S Truman »»»</pre>
 
=={{header|AutoHotkey}}==
<lang AutoHotkey>squeezable_string(str, char){
67

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.