Elegance is in the eye of the beholder. ;(>:i.5) (|.@[ <@{."0 1 <\) 'abcde' ┌─┬─┬─┬─┬─┬──┬──┬──┬──┬───┬───┬───┬────┬────┬─────┐ │a│b│c│d│e│ab│bc│cd│de│abc│bcd│cde│abcd│bcde│abcde│ └─┴─┴─┴─┴─┴──┴──┴──┴──┴───┴───┴───┴────┴────┴─────┘
R.E. Boss > -----Oorspronkelijk bericht----- > Van: Programming <programming-boun...@forums.jsoftware.com> > Namens Jimmy Gauvin > Verzonden: donderdag 24 oktober 2019 19:24 > Aan: programm...@jsoftware.com > Onderwerp: [Jprogramming] Consecutive substrings (was Quora problem) > > 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