A very neat solution.
Consider
george2=:3 :0
y =. ({~ ?~&#) y NB. shuffle
tree=. (<@{~ ?~&#)\ y
;@|."1 ' '&,&.> tree NB. pad
)
Compare
(george ,. george ,. george ,. george) 'abcde'
a a a a
b a a b a b a b
b a c c b a c b a c b a
c b a d a c b d a b d c a b c d
b c e a d d e a b c c d e a b b a d c e
(george2 ,. george2 ,. george2 ,. george2) 'abcde'
c d c a
c b d b c e a b
d c b d b e c e a e a b
e b d c e b a d e b c a a e d b
e b a d c d a b c e b d e c a a b e c d
On 2/28/2012 12:46 PM, Raul Miller wrote:
> Here is my first attempt at solving this:
>
> george=:3 :0
> tree=. (<@{~ ?~&#)\ y
> ;@|."1 ' '&,&.> tree NB. pad
> )
>
> george 'abcde'
> a
> a b
> c b a
> d c b a
> e a d b c
>
> Hopefully it is clear that the first line generates a scrambled tree,
> and the second line formats it for display.
>
> I think I prefer explicit definitions over other tacit forms, for
> implementations that use long chains of monads, because of the
> concatenative quality of explicit definitions.
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm