Jump to content

Determine if a string is collapsible: Difference between revisions

Line 599:
original : length = 8, string = «««😍😀🙌💃😍😍😍🙌»»»
collapsed: length = 6, string = «««😍😀🙌💃😍🙌»»»
</pre>
 
=={{header|J}}==
<pre>
STRINGS =: <;._2]0 :0
 
"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln
..1111111111111111111111111111111111111111111111111111111111111117777888
I never give 'em hell, I just tell the truth, and they think it's hell.
--- Harry S Truman
)
 
collapse =: (#~ (1 , 2 ~:/\ ])) ::(''"_) NB. copy dissimilar neighbors
assert 1 2 3 2 3 1 2 1 -: collapse 1 2 3 2 2 2 2 3 1 1 2 2 1 NB. test
 
task =: ,&(<@:(;~ (_6 + #)))&('<<<' , '>>>' ,~ ]) collapse NB. assemble the output
 
task&> STRINGS NB. operate on the data
+-----------------------------------------------------------------------------------+---------------------------------------------------------------------------------+
|+-+------+ |+-+------+ |
||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>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.