Yeah, I miscopied the code.

The original had >. and I used +

Same basic structure, but I never looked back to proofread my original
expression.

Also >. makes more sense than + in the context of that euler project.

Thanks,

-- 
Raul

On Sat, Jan 10, 2015 at 3:30 PM, Tikkanz <[email protected]> wrote:
> Should that be "pairwise maximum" rather than "pairwise sum"?
> On 10 Jan 2015 14:55, "Raul Miller" <[email protected]> wrote:
>
>> I guess I can do a low-level view of how the code works. Though I'm
>> not going to use sample data from euler 67 - have to leave you
>> something to do... instead, I'll use
>>
>>    i.3 3
>> 0 1 2
>> 3 4 5
>> 6 7 8
>>
>> as the sample data.
>>
>> So that's this:
>>    {. (+ 0: ,~ 2: >./\ ])/ i.3 3
>> 12
>>
>> We also don't need : after the numbers, for this particular case, in
>> modern versions of J, nor do we need the spaces, and I'm going to want
>> this to be compact, in a moment, so:
>>    {. (+0,~2>./\])/ i.3 3
>> 12
>>
>> Let's start breaking that down. First, let's remove the 'first' verb,
>> so we see what it is acting on:
>>
>>    (+0,~2>./\])/ i.3 3
>> 12 13 2
>>
>> Now how did that happen? Well, in this case the / operator inserts its
>> verb between the items of its noun. So, that is:
>>    0 1 2 (+0,~2>./\]) 3 4 5 (+0,~2>./\]) 6 7 8
>> 12 13 2
>>
>> Next, let's look at just one of these cases to see how it works:
>>
>>    3 4 5 (+0,~2>./\]) 6 7 8
>> 10 12 5
>>
>> So how does that work? Well, if we count the verbs in (+0,~2>./\])
>> there's an even number of them, so the top level structure is a hook.
>> And, it's a dyadic hook (with an argument on its left), so that means
>> we can just remove the parenthesis in that sentence (need to read the
>> documentation on hooks, really - I'm oversimplifying the definitions
>> for only their relevance in this case):
>>
>>    3 4 5 +0,~2>./\] 6 7 8
>> 10 12 5
>>
>> In other words, it's 3 4 5 + the result of the rest of that stuff.
>>
>> So:
>>    0,~2>./\] 6 7 8
>> 7 8 0
>>
>> That's the pair-wise sum of the elements of the list, with a zero
>> tacked onto the right hand side.
>>
>> Again, I'm oversimplifying things here - you should be able to perform
>> your own experiments and/or read the definitions either in the
>> official dictionary
>> http://www.jsoftware.com/help/dictionary/vocabul.htm or in the
>> unofficial nuvoc http://www.jsoftware.com/jwiki/NuVoc -- but be sure
>> to try things out, some, to help resolve ambiguities and especially
>> when you think you understand things (because sometimes things are
>> surprising).
>>
>> So anyways, {. (+ 0: ,~ 2: >./\ ])/ m is, basically:
>>
>> The first thing from:
>>
>>    adding each row to
>>       the pairwise sum of
>>          this result for the previous row
>>
>> (padding pairwise sums on the right, to keep things the same length)
>>
>> I hope this helps.
>>
>> Thanks,
>>
>> --
>> Raul
>>
>> On Sat, Jan 10, 2015 at 1:06 PM, Roger Hui <[email protected]>
>> wrote:
>> > Hmm, I bet you a Java solution would be longer, eh? :-)
>> >
>> > It's been years since I solve Project Euler 67, and I am busy with other
>> > things on the weekend, so there'll be a delay in a detailed description.
>> > Probably others will chime in meanwhile.
>> >
>> >
>> >
>> > On Sat, Jan 10, 2015 at 9:58 AM, oventarb oventarb <[email protected]>
>> > wrote:
>> >
>> >>
>> >> Dear Roger Hui!
>> >> I solved problem 67 using Java.
>> >> What does this code mean:
>> >>
>> >> {. (+ 0: ,~ 2: >./\ ])/ m
>> >> ----------------------------------------------------------------------
>> >> 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