13 :'(([: +/ [: *: -)"1& x)"1 y'
4 : '(([: +/ [: *: -)"1& x)"1 y'

13 : is not doing anything useful.

A f B is equivalent to
   (([: +/ [: *: -)"1& A)"1 B

So this is building up a function based on A which is being applied to
each row of B.  Note that it's first building up something based on
each row of A and that this something is being used on each row of B.
So we would expect the result to have a shape based on everything but
the last dimension of B followed by everything but the last dimension
of A followed by whatever the function itself produces.  And, testing,
we can see that this is the case:

   $A
3 2
   $B
4 4 2
   $(([: +/ [: *: -)"1& A)"1 B
4 4 3

So we get a number for each combination of row from A and row from B.

So, next, let's consider an arbitrary row from A (4 1) and an
arbitrary row from B (2 3):

   (([: +/ [: *: -)"1& (4 1))"1 (2 3)
8

Note that in this simplified case, we do not need the rank specifications:

   (([: +/ [: *: -)& 4 1)2 3
8

And, we can get rid of the & if we move the second argument to the
unoccupied side of the verb that & was modifying:

   2 3 ([: +/ [: *: -) 4 1
8

And, we can replace the train with an equivalent noun phrase, putting
the left and right arguments on each odd verb (counting from the
right) and eliminating any instances of [:

   +/ *: (2 3 - 4 1)
8

The parenthesis were not actually necessary here, but I included them
because the other odd verbs were all eliminated so I did not have any
place to show that parenthesis would be necessary.

So, anyways, we see that it's the sum of the squares of the difference
between the rows of A and the rows of B.

Here's an equivalent expression:

f=: +/@:*:@:-"1/~

Or, since you do not like @:

f=: [: +/"1 [: *: -"1/~

-- 
Raul

On Sun, Jun 3, 2012 at 10:03 PM, Linda Alvord <lindaalv...@verizon.net> wrote:
> Your result looks interesting and I am able to get a tree from  5!:4 <'waveR'.
>
> Here's a real issue for me! What is function  f  doing to product the result 
> you get?
>
>   A=:3 2$3 3 4 1 1 3
>   B=:(i.4),."0 1 i.4
>   f=: 13 :'(([: +/ [: *: -)"1& x)"1 y'
>   A f B
> 18 17 10
> 13 16  5
> 10 17  2
>  9 20  1
>
> 13 10  9
>  8  9  4
>  5 10  1
>  4 13  0
>
> 10  5 10
>  5  4  5
>  2  5  2
>  1  8  1
>
>  9  2 13
>  4  1  8
>  1  2  5
>  0  5  4
>
>   5!:4 <'f'
>      ┌─ 4
> ── : ─┴─ ,:'(([: +/ [: *: -)"1& x)"1 y'
>
> When there is some way to untangle this so I can figure out what is 
> happening? I find the tree diagrams helpful but some code makes that 
> impossible.
>
> Can you give a simple translation for this function.
>
> Thanks in advance.
>
> Linda
>
>
> -----Original Message-----
> From: programming-boun...@jsoftware.com 
> [mailto:programming-boun...@jsoftware.com] On Behalf Of Raul Miller
> Sent: Sunday, June 03, 2012 11:23 AM
> To: Programming forum
> Subject: Re: [Jprogramming] Challenge 11 Wave the Flag
>
> If by simplification you mean "fewer tokens while avoiding text definitions 
> and @ and @: then here is a variation on Jose's approach:
>
>  waveR=: [:<"_1 [:|.&|:^:4 3 2 1 0 [:(|."_1~ [:>. +/ .=&' ' % _2:) [:> ;:
>
> I save 3 tokens by replacing (<5) with 4 3 2 1 0
>
> I save 2 tokens by replacing
>   [: - [: <. [: -: ' '+/ .=~
> with
>   [: >. +/ .=&' ' % _2:
>
> I save 2 tokens by replacing
>   ([: |. |:)
> with
>   |.&|:
>
> Note, however that if you are purely counting tokens, u@v and u@:v can be 
> simpler than ([: u v).
>
> Also, if you count text as a single token, text definitions are automatically 
> simpler than most everything.  (But if you add to the token count the number 
> of tokens represented in the text, this goes
> away.)
>
> --
> Raul
>
> On Sun, Jun 3, 2012 at 10:23 AM, Linda Alvord <lindaalv...@verizon.net> wrote:
>>
>> Viktor Cerovski and Jose Quintanta have provided solutions that are
>> simplifying the waves.
>>
>>   B=:'a big arrow focused somewhere'
>>   wave=: [: <"2 [: ([: |: |.)^:(<5) ([: > ;:)|."0 1~ [: - [: <. [: -: [:
>> +/"1 ' ' = [: > ;:
>>   #;:'[: <"2 [: ([: |: |.)^:(<5) ([: > ;:) |."0 1~ [: - [: <. [: -: [:
>> +/"1 '' '' = [: > ;:'
>> 40
>>   waveVC=:[: <"2 [: ([: |: |.)^:(<5) [: (|."0 1~ [: - [: <. [: -: [: +/"1 '
>> ' = ]) [: > ;:
>>   #;:'[: <"2 [: ([: |: |.)^:(<5) [: (|."0 1~ [: - [: <. [: -: [: +/"1 '' ''
>> = ]) [: > ;'
>> 39
>>   waveJQ=.[: <"2 [: ([: |: |.)^:(<5) [: (|."0 1~ [: - [: <. [: -: '
>> '+/ .=~
>> ]) [: > ;:
>>   #;:'[: <"2 [: ([: |: |.)^:(<5) [: (|."0 1~ [: - [: <. [: -: '' ''+/
>> .=~
>> ]) [: > ;:'
>> 38
>>   Any more simplifications waiting in thewings?
>>
>> Linda
>>
>> -----Original Message-----
>> From: programming-boun...@jsoftware.com
>> [mailto:programming-boun...@jsoftware.com] On Behalf Of Jose Quintana
>> Sent: Sunday, June 03, 2012 12:33 AM
>> To: programming@jsoftware.com
>> Subject: Re: [Jprogramming] Challenge 11 Wave the Flag
>>
>>
>> Cheating...    wave1=. [: <"2 [: ([: |: |.)^:(<5) [: (|."0 1~ [: - [: <. [:
>> -: ' ' +/ .=~ ]) [: > ;:
>>
>>   cheat=. (lr<'wave1')&apply f.
>>   lr<'cheat'
>> '[: <"2 [: ([: |: |.)^:(<5) [: (|."0 1~ ([: - [: <. [: -: '' '' +/ .=~
>> ]))
>> [: > ;:'&(128!:2)
>>   #;:lr<'cheat'
>> 7
>> ... and without cheating
>>   wave1=. [: <"2 [: ([: |: |.)^:(<5) [: (|."0 1~ [: - [: <. [: -: ' '
>> +/ .=~ ]) [: > ;:
>>   #;:    '[: <"2 [: ([: |: |.)^:(<5) [: (|."0 1~ [: - [: <. [: -: ''
>> '' +/ .=~ ]) [: > ;:'
>> 38    > Date: Sat, 2 Jun 2012 02:38:40 -0700
>>> From: viktor.cerov...@gmail.com
>>> To: programming@jsoftware.com
>>> Subject: Re: [Jprogramming] Challenge 11 Wave the Flag
>>>
>>>
>>>
>>>
>>> Linda Alvord wrote:
>>> >
>>> >
>>> >
>>> > It was David Ward Lambert's idea to write a one line expression
>>> > with the fewest tokens.  We worked together and got to 40 tokens.
>>> > Any ideas to make this any better.
>>> >
>>> >
>>> >
>>> >    B=:'a big arrow focused somewhere'
>>> >
>>> >    NB.  center justify (Hint from DWL  x |."0 1 y)
>>> >
>>> >    cj=: 13 :'(-<.-:+/"1 '' ''=>;:y)|."0 1>;:y'
>>> >
>>> >    cj
>>> >
>>> > ([: - [: <. [: -: [: +/"1 ' ' = [: > ;:) |."0 1 [: > ;:
>>> >
>>> >    cj B
>>> >
>>> >     a
>>> >    big
>>> >   arrow
>>> >  focused
>>> > somewhere
>>> >
>>> >    NB. quarter turns
>>> >
>>> >    qtla=: 13 :'y;(|:|.y);(|.|:|.|:y);(|.|:y);y'
>>> >
>>> >    qtla
>>> >
>>> > ] ; ([: |: |.) ; ([: |. [: |: [: |. |:) ; ] ;~ [: |. |:
>>> >
>>> >    qtla cj B
>>> >
>>> > ----------T-----T---------T-----T---------┐
>>> > │    a    │s    │erehwemos│    e│    a    │ │   big   │of   │
>>> > desucof │   dr│   big   │ │  arrow  │moa  │  worra  │  wee│  arrow
>>> > │ │ focused │ecrb │   gib   │ gosh│ focused │ │somewhere│wuria│
>>> > a    │airuw│somewhere│ │         │hsog │         │ brce│         │
>>> > │         │eew  │         │  aom│         │ │         │rd   │
>>> > │   fo│         │ │         │e    │         │    s│         │
>>> > L---------+-----+---------+-----+----------
>>> >
>>> >    NB. 5 quarter turns David Ward Lambert
>>> >
>>> >    qtdwl=: 13 :'<"2 ([:|:|.)^:(<5)y'
>>> >
>>> >    qtdwl cj B
>>> >
>>> > ----------T---------T---------T---------T---------┐
>>> > │    a    │s        │erehwemos│    e    │    a    │ │   big   │of
>>> > │ desucof │   dr    │   big   │ │  arrow  │moa      │  worra  │
>>> > wee    │  arrow  │ │ focused │ecrb     │   gib   │ gosh    │
>>> > focused │ │somewhere│wuria    │    a    │airuw    │somewhere│ │
>>> > │hsog     │         │ brce    │         │ │         │eew      │
>>> > │  aom    │         │ │         │rd       │         │   fo    │
>>> > │ │         │e        │         │    s    │         │
>>> > L---------+---------+---------+---------+----------
>>> >
>>> >    qtdwl
>>> >
>>> > [: <"2 ([: |: |.)^:(<5)
>>> >
>>> >
>>> >
>>> >    wave=: [: <"2 [: ([: |: |.)^:(<5) ([: > ;:)|."0 1~ [: - [: <. [: -:
>> [:
>>> > +/"1 ' ' = [: > ;:
>>> >
>>> >
>>> Here is a 39 token version:
>>>
>>>    wave1=:[: <"2 [: ([: |: |.)^:(<5) [: (|."0 1~ [: - [: <. [: -: [:
>>> +/"1
>> '
>>> ' = ]) [: > ;:
>>>
>>>    #;:'[: <"2 [: ([: |: |.)^:(<5) [: (|."0 1~ [: - [: <. [: -: [: +/"1 ''
>> ''
>>> = ]) [: > ;:'
>>> 39
>>>
>>>
>>>
>>> >
>>> >    wave B
>>> >
>>> > ----------T---------T---------T---------T---------┐
>>> > │    a    │s        │erehwemos│    e    │    a    │ │   big   │of
>>> > │ desucof │   dr    │   big   │ │  arrow  │moa      │  worra  │
>>> > wee    │  arrow  │ │ focused │ecrb     │   gib   │ gosh    │
>>> > focused │ │somewhere│wuria    │    a    │airuw    │somewhere│ │
>>> > │hsog     │         │ brce    │         │ │         │eew      │
>>> > │  aom    │         │ │         │rd       │         │   fo    │
>>> > │ │         │e        │         │    s    │         │
>>> > L---------+---------+---------+---------+----------
>>> >
>>> >    wave
>>> >
>>> > [: <"2 [: ([: |: |.)^:(<5) ([: > ;:) |."0 1~ [: - [: <. [: -: [: +/"1 '
>> '
>>> > =
>>> > [: > ;:
>>> >
>>> >    #;:'[:<"2[:([:|:|.)^:(<5)([:>;:)|."0 1~[:-[:<.[:-:[:+/"1'' ''=[:>;:'
>>> >
>>> > 40
>>> >
>>> >
>>> >
>>> > Hopefully David will send his version of 39 tokens but not simple J.
>>> > Note also that you must paste the long line for wave together.
>>> >
>>> >
>>> >
>>> > Linda
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > From: Linda Alvord [mailto:lindaalv...@verizon.net]
>>> > Sent: Tuesday, May 01, 2012 3:17 AM
>>> > To: 'Linda Alvord'
>>> > Subject: Challenge 11 Wave the Flag
>>> >
>>> >
>>> >
>>> > Challenge 10 Wave the Flag    PLEASE DO NOT RESPOND UNTIL 5/28/2012
>>> > 12
>> am
>>> > EST
>>> >
>>> >
>>> >
>>> > Here's a little preparation for Memorial Day.
>>> >
>>> >
>>> >
>>> >   S=:10 16$(16$' '),176$(16$'*  '),16$' * '
>>> >
>>> >    T=:10 36$(36$'#'),72$' '
>>> >
>>> >    U=:9 52$(104$' '),364$(52$'#'),104$' '
>>> >
>>> >    <' ',"1(((S,"1 ' '),.T),U),"1 ' '
>>> >
>>> > --------------------------------------------------------┐
>>> > │                  #################################### │ │ *  *  *
>>> > *  *  *                                      │ │  *  *  *  *  *
>>> > │ │ *  *  *  *  *  * #################################### │ │  *  *
>>> > *  *  *                                        │ │ *  *  *  *  *  *
>>> > │ │  *  *  *  *  *   #################################### │ │ *  *
>>> > *  *  *  *                                      │ │  *  *  *  *  *
>>> > │ │ *  *  *  *  *  * #################################### │ │
>>> > │ │                                                       │ │
>>> > ####################################################  │ │
>>> > │ │                                                       │ │
>>> > ####################################################  │ │
>>> > │ │                                                       │ │
>>> > ####################################################  │
>>> > L--------------------------------------------------------
>>> >
>>> >
>>> >
>>> > Part 1:  Use viewmat and create a little flag. Next design a
>>> > function to rotate it clockwise 90 degrees successively until it is
>>> > in the original position.
>>> >
>>> >
>>> >
>>> >    load viewmat
>>> >
>>> >    flag=:
>>> >
>>> > wwwwwwww
>>> > wwwwwwww
>>> > wwwwwwww
>>> > wwwwwwww
>>> >
>>> > wwwwwwwwwwwwww
>>> >
>>> > wwwwwwww
>>> > wwwwwwww
>>> > wwwwwwww
>>> > wwwwwwww
>>> >
>>> > wwwwwwwwwwwwww
>>> >
>>> > wwwwwwww
>>> > wwwwwwww
>>> > wwwwwwww
>>> > wwwwwwww
>>> >
>>> > wwwwwwwwwwwwww
>>> >
>>> > wwwwwwww
>>> > wwwwwwww
>>> > wwwwwwww
>>> > wwwwwwww
>>> >
>>> > wwwwwwwwwwwwww
>>> >
>>> > wwwwwwww
>>> > wwwwwwww
>>> > wwwwwwww
>>> > wwwwwwww
>>> >
>>> >
>>> >
>>> > Part 2:
>>> >
>>> >
>>> >
>>> >    A=:'we celebrate Memorial Day on May the twenty eighth'
>>> >
>>> >    wave=:
>>> >
>>> > ------------T-----------T-----------T-----------T-----------┐
>>> > │----------┐│----------┐│----------┐│----------┐│----------┐│
>>> > ││   we    │││      Mc │││  hthgie │││ e       │││   we    ││
>>> > ││celebrate│││et    ee │││  ytnewt │││ tl      │││celebrate││
>>> > ││Memorial │││iw    ml │││   eht   │││ aa    yh│││Memorial ││ ││
>>> > Day   │││getMoDoew│││   yaM   │││ riy yett│││   Day   ││ ││   on
>>> > │││hnhanarbe│││    no   │││ebranahnh│││   on    ││ ││   May
>>> > │││ttey yir │││   yaD   │││weoDoMteg│││   May   ││ ││   the   │││hy
>>> > aa │││ lairomeM│││ lm    wi│││   the   ││ ││ twenty  │││      lt
>>> > │││etarbelec│││ ee    te│││ twenty  ││ ││ eighth  │││       e │││
>>> > ew   │││ cM      │││ eighth  ││
>>> > │L----------│L----------│L----------│L----------│L----------│
>>> > L-----------+-----------+-----------+-----------+------------
>>> >
>>> >
>>> >
>>> > Reshape A into a 9 9 square matrix. Justify all lines in the center.
>>> > If a line has an even number of letters put the extra letter on the
>>> > left. Now design a function to rotate the words in a similar
>>> > fashion to the flag above.  Note the letters in "we" as they move
>>> > around clockwise. Your function should work for any square literal matrix.
>>> >
>>> >
>>> >
>>> > Happy Memorial Day!
>>> >
>>> >
>>> >
>>> > Linda
>>> >
>>> > -------------------------------------------------------------------
>>> > -
>>> > -- For information about J forums see
>>> > http://www.jsoftware.com/forums.htm
>>> >
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Re%3A-Challenge-11-Wave-the-Flag-tp33948875s241
>>> 9 3p33948951.html Sent from the J Programming mailing list archive at
>>> Nabble.com.
>>>
>>> ---------------------------------------------------------------------
>>> - 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
> ----------------------------------------------------------------------
> 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