Linda, I'm embarrassed that I didn't see

     rtp =: [: sh&> [: <\ [: sh <"_1  NB. rt using prefix

     a
  abcdef

     rtp a
  +-+-+-+-+-+-+
  |b| | | | | |
  +-+-+-+-+-+-+
  |c|b| | | | |
  +-+-+-+-+-+-+
  |c|f|b| | | |
  +-+-+-+-+-+-+
  |b|f|e|c| | |
  +-+-+-+-+-+-+
  |f|e|c|b|d| |
  +-+-+-+-+-+-+
  |f|e|b|c|a|d|
  +-+-+-+-+-+-+

Raul has explained "0 _ .  In effect I was re-inventing <\. (box suffix) .

In rtp above, (sh <"_1 y) randomly chooses the items which are added as 
we move down the triangle, and (<\ sh <"_1 y) creates unshuffled partial 
rows for the triangle, enclosing each partial row in a box.  Finally, 
(sh&> <\ sh <"1 y) opens each box, one at time, and shuffles the partial 
row that was inside.  J automatically assembles the shuffled partial 
rows into the final result, appending empty boxes to the end of each 
shuffled partial row so the final rows all have the same length.  Your 
attempt below omits the important step of shuffling each partial row. 
(Notice that in the result of rtla the new element in each row is always 
added to the end of the preceding row.)

The argument y can be any array.

     ]d =: 3 2 4 $ 'Now is  the timefor all '
  Now
  is

  the
  time

  for
  all
     rtp d
  +----+----+----+
  |the |    |    |
  |time|    |    |
  +----+----+----+
  |for |the |    |
  |all |time|    |
  +----+----+----+
  |for |Now |the |
  |all |is  |time|
  +----+----+----+

Kip

On 2/24/2012 1:10 AM, Linda Alvord wrote:
> You have me baffled long before I get to  i
>
>     sh =: ?&#~ { ] NB. shuffle
>     sh
> ?&#~ { ]
>     sh2=: 13 :'(y?&#y) { y'
>     sh2
> ?&#~ { ]
>     shla=: 13 :'((#y)?#y){y'
>     shla
> ] {~ # ? #
>     ]shla 'abcde'
> dbace
>
>      rt =: [: |. [:sh&>  i.@#<@}."0 _ [: sh<"_1  NB. right triangle
>      rt
> [: |. [: sh&>  i.@#<@}."0 _ [: sh<"_1
>     rt 'abcde'
> --T-T-T-T-┐
> │c│ │ │ │ │
> +-+-+-+-+-+
> │c│e│ │ │ │
> +-+-+-+-+-+
> │c│b│e│ │ │
> +-+-+-+-+-+
> │c│d│b│e│ │
> +-+-+-+-+-+
> │a│d│c│b│e│
> L-+-+-+-+--
>     rt2=: 13 :'<"0 |.(i.#y)}."0 _ sh y'
>     rt2
> [:<"0 [: |. ([: i. #) }."0 _ sh
>     rt2 'abcde'
> --T-T-T-T-┐
> │a│ │ │ │ │
> +-+-+-+-+-+
> │d│a│ │ │ │
> +-+-+-+-+-+
> │b│d│a│ │ │
> +-+-+-+-+-+
> │c│b│d│a│ │
> +-+-+-+-+-+
> │e│c│b│d│a│
> L-+-+-+-+--
>     rtla=: 13 :'<"0 ,\sh y'
>     rtla
> [:<"0 [: ,\ sh
>     rtla 'abcde'
> --T-T-T-T-┐
> │d│ │ │ │ │
> +-+-+-+-+-+
> │d│c│ │ │ │
> +-+-+-+-+-+
> │d│c│a│ │ │
> +-+-+-+-+-+
> │d│c│a│b│ │
> +-+-+-+-+-+
> │d│c│a│b│e│
> L-+-+-+-+--
>
> I used  infix  and got your  rt  .  But here is what I don't understand.
> What is going on in  a  ?  If I remove  _  it doesn't work.  When it is
> there I can't figure out what you've done.
>
>     a=: 13 :'(i.#y)}."0 _ sh y'
>     a 'abcde'
> cbaed
> baed
> aed
> ed
> d
>
> Linda
>
> -----Original Message-----
> From: programming-boun...@jsoftware.com
> [mailto:programming-boun...@jsoftware.com] On Behalf Of Kip Murray
> Sent: Wednesday, February 22, 2012 12:24 AM
> To: Programming forum
> Subject: Re: [Jprogramming] Challenge 6 Many Many Cherry Trees
>
>       NB. Linda's Challenge 6
>
>
>       oit rt 'abcdef'
>         f
>        a f
>       e a f
>      f a d e
>     f a e d c
>    f e a b d c
>
>       oit rt 1 2 3 4 5 6
>         6
>        1 6
>       1 4 6
>      1 2 4 6
>     4 1 6 2 3
>    6 5 4 2 3 1
>
>
>       NB. Details follow, restrictions noted at end
>
>
>       sh =: ?&#~ { ]  NB. shuffle
>
>       rt =: [: |. [: sh&>  i.@#<@}."0 _ [: sh<"_1  NB. right triangle
>
>       ]a =: 'abcdef'
>    abcdef
>
>       ]art =: rt a
>    +-+-+-+-+-+-+
>    |b| | | | | |
>    +-+-+-+-+-+-+
>    |c|b| | | | |
>    +-+-+-+-+-+-+
>    |c|b|a| | | |
>    +-+-+-+-+-+-+
>    |c|e|b|a| | |
>    +-+-+-+-+-+-+
>    |c|e|a|d|b| |
>    +-+-+-+-+-+-+
>    |f|c|a|b|d|e|
>    +-+-+-+-+-+-+
>
>       ]b =: 1 2 3 4 5 6
>    1 2 3 4 5 6
>
>       ]brt =: rt b
>    +-+-+-+-+-+-+
>    |5| | | | | |
>    +-+-+-+-+-+-+
>    |2|5| | | | |
>    +-+-+-+-+-+-+
>    |2|6|5| | | |
>    +-+-+-+-+-+-+
>    |6|4|2|5| | |
>    +-+-+-+-+-+-+
>    |4|5|1|2|6| |
>    +-+-+-+-+-+-+
>    |3|1|4|5|6|2|
>    +-+-+-+-+-+-+
>
>
>       ia =: ([ , a: , ])/  NB. insert a:
>
>       it =: 3 : 0 " 1  NB. isosceles triangle from right triangle
>       xx =. y i. a:
>       ((-xx-#y) # a:), ia xx {. y
>       )
>
>       it art
>    +-+-+-+-+-+-+-+-+-+-+-+
>    | | | | | |b| | | | | |
>    +-+-+-+-+-+-+-+-+-+-+-+
>    | | | | |c| |b| | | | |
>    +-+-+-+-+-+-+-+-+-+-+-+
>    | | | |c| |b| |a| | | |
>    +-+-+-+-+-+-+-+-+-+-+-+
>    | | |c| |e| |b| |a| | |
>    +-+-+-+-+-+-+-+-+-+-+-+
>    | |c| |e| |a| |d| |b| |
>    +-+-+-+-+-+-+-+-+-+-+-+
>    |f| |c| |a| |b| |d| |e|
>    +-+-+-+-+-+-+-+-+-+-+-+
>
>       it brt
>    +-+-+-+-+-+-+-+-+-+-+-+
>    | | | | | |5| | | | | |
>    +-+-+-+-+-+-+-+-+-+-+-+
>    | | | | |2| |5| | | | |
>    +-+-+-+-+-+-+-+-+-+-+-+
>    | | | |2| |6| |5| | | |
>    +-+-+-+-+-+-+-+-+-+-+-+
>    | | |6| |4| |2| |5| | |
>    +-+-+-+-+-+-+-+-+-+-+-+
>    | |4| |5| |1| |2| |6| |
>    +-+-+-+-+-+-+-+-+-+-+-+
>    |3| |1| |4| |5| |6| |2|
>    +-+-+-+-+-+-+-+-+-+-+-+
>
>
>       vertchars =: 25 124 { a.
>
>       oit =: 3 : 0
>
>       NB. produces open isosceles triangle from boxed right triangle y
>
>       rc =. 1:`{.@.(2=#) $ y   NB. row count
>
>       dhr =.<: {. $ ": 0 { y  NB. decrement height of row display
>
>       mhb =. (>: rc * dhr) $ 0 , (<: dhr) # 1 NB. mask for horz boundaries
>
>       NB. now remove horz then vert boundaries from display of (it y)
>
>       vertchars -."1~ mhb # ": it y
>       )
>
>       oit art
>         b
>        c b
>       c b a
>      c e b a
>     c e a d b
>    f c a b d e
>
>       oit brt
>         5
>        2 5
>       2 6 5
>      6 4 2 5
>     4 5 1 2 6
>    3 1 4 5 6 2
>
>       ]c =: 6 4 $ 'Now is  the timefor all '
>    Now
>    is
>    the
>    time
>    for
>    all
>
>       ]crt =: rt c
>    +----+----+----+----+----+----+
>    |Now |    |    |    |    |    |
>    +----+----+----+----+----+----+
>    |Now |for |    |    |    |    |
>    +----+----+----+----+----+----+
>    |is  |for |Now |    |    |    |
>    +----+----+----+----+----+----+
>    |the |Now |is  |for |    |    |
>    +----+----+----+----+----+----+
>    |is  |Now |for |all |the |    |
>    +----+----+----+----+----+----+
>    |all |time|the |Now |for |is  |
>    +----+----+----+----+----+----+
>
>       oit crt
>                        Now
>                    Now     for
>                is      for     Now
>            the     Now     is      for
>        is      Now     for     all     the
>    all     time    the     Now     for     is
>
>       ]d =: 3 2 4 $ 'Now is  the timefor all '
>    Now
>    is
>
>    the
>    time
>
>    for
>    all
>
>       ]drt =: rt d
>    +----+----+----+
>    |the |    |    |
>    |time|    |    |
>    +----+----+----+
>    |Now |the |    |
>    |is  |time|    |
>    +----+----+----+
>    |the |for |Now |
>    |time|all |is  |
>    +----+----+----+
>
>       oit drt
>            the
>            time
>        Now     the
>        is      time
>    the     for     Now
>    time    all     is
>
>
>    NB. For verb oit to work, arguments to verb rt need to be open and
>    NB. free of vertchars.  I leave it as an exercise to remove these
>    NB. requirements!
>
>
>    Kip Murray
>
> On 2/14/2012 3:54 AM, Linda Alvord wrote:
>> Challenge 6 Many Many Cherry Trees   PLEASE DO NOT RESPOND UNTIL 2/22/2012
>> 12 am EST
>>
>>
>>
>>
>>
>> If necessary, ask questions, but try not to give away your strategy for
>> solving the challenge.
>>
>>
>>
>> Design a function with no restrictions on style or specific functions.
>>
>> It should produce a triangle similar to the ones shown below. Each row is
> a
>> successive scramble of the character string above it with one added
> symbol.
>> The  final line is a scramble of the entire list.
>>
>>
>>
>>     gw 'many'
>>
>>      a
>>     a n
>>    a y n
>>   a m y n
>>
>>
>>
>>     gw 'many'
>>
>>      m
>>     y m
>>    y a m
>>   n a m y
>>
>>
>>
>>    gw 'cherrytrees'
>>
>>             s
>>            r s
>>           h s r
>>          h r s y
>>         y s r e h
>>        e h r s r y
>>       y r e s h e r
>>      s e r r e y e h
>>     e s t e r e y h r
>>    r e r s t r y e e h
>>   e r c r h y r e t s e
>>
>>      a=:gw '%%%####'
>>
>>      a,.a,.a,.a
>>
>>         %             %             %             %
>>        % #           % #           % #           % #
>>       % # %         % # %         % # %         % # %
>>      % # # %       % # # %       % # # %       % # # %
>>     # % # % #     # % # % #     # % # % #     # % # % #
>>    # % # % % #   # % # % % #   # % # % % #   # % # % % #
>>   # % # # # % % # % # # # % % # % # # # % % # % # # # % %
>>
>>
>>
>> Linda
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> 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