Removing the empty cells:

a#~-.(<'')=a=.,(>:i.5)<\'abcde'

│a│b│c│d│e│ab│bc│cd│de│abc│bcd│cde│abcd│bcde│abcde│


I'm sure this can be reduced by J experts in implicit coding.


Skip


On Thu, Oct 24, 2019 at 12:23 PM Jimmy Gauvin <[email protected]>
wrote:

> Hi,
>
> I was wondering if there was some way to emulate R.E.Boss's elegant code to
> generate all the substrings of consecutive elements of a vector :
>
>    <@(<\.)\'abcde'
> ┌───┬──────┬──────────┬───────────────┬─────────────────────┐
> │┌─┐│┌──┬─┐│┌───┬──┬─┐│┌────┬───┬──┬─┐│┌─────┬────┬───┬──┬─┐│
> ││a│││ab│b│││abc│bc│c│││abcd│bcd│cd│d│││abcde│bcde│cde│de│e││
> │└─┘│└──┴─┘│└───┴──┴─┘│└────┴───┴──┴─┘│└─────┴────┴───┴──┴─┘│
> └───┴──────┴──────────┴───────────────┴─────────────────────┘
>    ;<@(<\.)\'abcde'
> ┌─┬──┬─┬───┬──┬─┬────┬───┬──┬─┬─────┬────┬───┬──┬─┐
> │a│ab│b│abc│bc│c│abcd│bcd│cd│d│abcde│bcde│cde│de│e│
> └─┴──┴─┴───┴──┴─┴────┴───┴──┴─┴─────┴────┴───┴──┴─┘
>
> Using infix with all the substring lengths almost gets us there but there
> are a lot of empty cells :
>    , (>:i.5) <\'abcde'
> ┌─┬─┬─┬─┬─┬──┬──┬──┬──┬┬───┬───┬───┬┬┬────┬────┬┬┬┬─────┬┬┬┬┐
> │a│b│c│d│e│ab│bc│cd│de││abc│bcd│cde│││abcd│bcde││││abcde│││││
> └─┴─┴─┴─┴─┴──┴──┴──┴──┴┴───┴───┴───┴┴┴────┴────┴┴┴┴─────┴┴┴┴┘
>
> Is there an elegant way of eliminating the empty cells ?
>
> Thanks,
>
> Jimmy
>
> PS Adding oblique and transpose gives the same order as R.E.Boss's
> expression :
>    ; <@, /. |: (>:i.5) <\'abcde'
> ┌─┬──┬─┬───┬──┬─┬────┬───┬──┬─┬─────┬────┬───┬──┬─┬┬┬┬┬┬┬┬┬┬┐
> │a│ab│b│abc│bc│c│abcd│bcd│cd│d│abcde│bcde│cde│de│e│││││││││││
> └─┴──┴─┴───┴──┴─┴────┴───┴──┴─┴─────┴────┴───┴──┴─┴┴┴┴┴┴┴┴┴┴┘
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to