I have worked through the solution arrived at by a few of you to better learn J, namely this one:
+/,(57=x+/y+/z)*x</y*y</z In order to fully understand the way the matrix operations are carried out, I minimized the answer space by making P = 13, and worked through the output (not shown for brevity's sake) of the following input lines I placed in a project file (learning the IDE with this problem too): P =: 13 x =: >:i.4 y =: >:x z =: >:y 3 4 $ x,y,z (13=x+/y+/z)*x</y*y</z +/,(13=x+/y+/z)*x</y*y</z +/,((13=[+/+/)*[</]*</)~i.7 I need to work on the last bit with the [</] in it, and the use of ~ here. It is sometimes hard for a beginner to realize where one word begins and another ends, or if they are combinations (dyads). It took me a while to get the * as a selector across the +'s inserted (/) over x, y and z. I tried replacing +/, with #, and #, but received a different answer for the solution with the ~i.7 at the end. Anyway, I was tempted to try and make the J program look like the Perl oneby using for. but I realized I was lapsing into old habits. My minimal programming experience is all with imperative languages or some Lisp too. My next question is how do you get the J program to print the solutions as in the Perl program? In my 3 x 4 matrices of the reduced problem set, I could see how the 1's in the solution selection matrix set related to the original 3 x 4 matrix of x, y and z rows. Without re-writing it, is there a way to index the solution? One question that is on my mind is the tacit vs. explicit style. I am in love with the way you all distill the solution down to a tacit one-liner, just as a maths formula is simplified, however, I am starting to think that if and when I revisit this problem in the future, it will take a bit of jarring to read it, translate it if you will. I am guessing for. loops are very expensive cycle-wise and it would be just as easy to make words for phrases if I wish to preserve future readability. I am getting addicted to the fast way of working in the J environment, and I am grateful to all on this list for sharing their wisdom. Rob On Sun, May 26, 2013 at 8:48 PM, Olivier N. < [email protected]> wrote: > > In Elton Wang's implementation, I can see one trivial change that might > help: > > > >> +/+/+/(57=x+/y+/z)*x</y*y</z > >> Where x=.y=.z=i.29 > > > > could instead use > > +/,(57=x+/y+/z)*x</y*y</z > > Oh yes, good point. > Is there a way to test resource (cpu, mem, time) usage within J? > > > or, if you prefer > > +/,((57=[+/+/)*[</]*</)~i.29 > > That was a huge step for me. Thanks for pushing me! > > As I understand it, you first use the fact that x equals y equals z > (don't know yet how to represent it correctly in J) then you replace > z with [ and ]. That's the main difficulty for me as it changes the > structure from something linear (reading-wise) to embedded trains. > > Then I tried to create the corresponding function and used @ > (or should I use @: … rank usage is not perfectly clear for > me yet) creating new forks to avoid an unwanted one: > > fun =: +/@,@((57=[+/+/)*[</]*</)~@i. > > (9!: helped me to check I did it right, thanks!) > > I was surprised a few times by this expression: > > 1. the ~ applies to the whole left fork > instead of just to the parentheses! > > 2. at first I thought I should add a & so that I got > (57&=[+/+/) but it didn't worked as expected > > 3. is there a reason to use [ *and* ] instead of only ] ? > > > (It's interesting to think about why I used [</] instead of </ > > I tried to understand. Is it because the form with [</] is > equivalent to rank 3 “z </ z * (z</z)” but </ only leads > to rank 2 “(z</z) * (z</z)”? > > I'm still trying to convert it to a function I could use directly: > > nfun 57 > > This seems a good exercice but might take me some time to solve. > > Thanks again. > > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
