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: [email protected]
[mailto:[email protected]] 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 <[email protected]> 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: [email protected]
> [mailto:[email protected]] On Behalf Of Jose Quintana
> Sent: Sunday, June 03, 2012 12:33 AM
> To: [email protected]
> 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: [email protected]
>> To: [email protected]
>> 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:[email protected]]
>> > 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