Determine if a string is squeezable: Difference between revisions
no edit summary
(Added XPL0 example.) |
No edit summary |
||
Line 2,149:
└──────────────────────────────────────────────────────────────────────────────┘
</lang>
=== APL translation ===
{{trans|APL}}▼
<lang J>NB. Note |.!.1 here instead of the APL version's 1 , }. to more elegantly handle the null case in J▼
sq =: ] #~ ~: +. _1 |.!.1 ] ~: 1 |. ]</lang>▼
'''Run''':▼
<lang j>require'format/printf' NB. For formatting the output▼
'C I' =: <"1 |: P =: ; ;"0 1^:(0<#@[)&.>/"1 (({.~ ; (}.~>:)) i.&'|')&> LF cut noun define▼
|▼
-|"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln ▼
7|..1111111111111111111111111111111111111111111111111111111111111117777888▼
.|I never give 'em hell, I just tell the truth, and they think it's hell. ▼
-r| --- Harry S Truman ▼
)▼
S =: sq&.>/"1 P▼
smoutput 'chr: ''%s''\nin: %d «««%s»»»\nout: %d «««%s»»»\n' sprintf C ,. (#&.>I),.I ,. (#&.>S),.S</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|Java}}==
<lang Java>
Line 2,298 ⟶ 2,343:
Original: «««SabcSS:SSdefSSSghSS»»» has length 19
result is «««SabcS:SdefSghS»»» with length 14</lang>
▲{{trans|APL}}
▲<lang J>NB. Note |.!.1 here instead of the APL version's 1 , }. to more elegantly handle the null case in J
▲sq =: ] #~ ~: +. _1 |.!.1 ] ~: 1 |. ]</lang>
▲'''Run''':
▲<lang j>require'format/printf' NB. For formatting the output
▲'C I' =: <"1 |: P =: ; ;"0 1^:(0<#@[)&.>/"1 (({.~ ; (}.~>:)) i.&'|')&> LF cut noun define
▲|
▲-|"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln
▲7|..1111111111111111111111111111111111111111111111111111111111111117777888
▲.|I never give 'em hell, I just tell the truth, and they think it's hell.
▲ -r| --- Harry S Truman
▲)
▲S =: sq&.>/"1 P
▲smoutput 'chr: ''%s''\nin: %d «««%s»»»\nout: %d «««%s»»»\n' sprintf C ,. (#&.>I),.I ,. (#&.>S),.S</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|Julia}}==
|