Randy MacDonald wrote:
> Does (0>.])y not work?
>
It works, no problem!
Here's what I had so far:
Gmine=: +/P*(*0&<:)D<.(,-&B) BL
and after the advise of Devon it evolved to a better:
GNext=: +/P*0>.D<.(,-&B) BL
As you'll notice, the better solution, which I didn't
notice ;-) lies just at the RH of it in my sentence:
D<.result (selecting the minimum: kind of an equivalent
sub problem)). Well, that's a lesson learned. No doubt
there will be much cleverer solutions to this all. The most
important goal for me was translating the explicit imperative
solution I started with:
Gxpl=: 3 : 0
i=.0
R=.y
s=.0
while. 0<:R do.
R=.R-i{D
s=.s+(i{D + (]`0:@.(0<:])) R)*i{P
i=.i+1
end.
s
)
to the tacit solution Gmine. And in this struggle
one the subjects I encountered was how to recognize
and formulate a hook. That's an important lesson for me.
I know it's all in J4C by Henry Rich, but I didn't find
(or overlooked) the variant (v1 m v2 v3) y.
Formulating the sub-problem: zeroing negative values
y*(0<:y)
to the hook:
(*0&<:)
And not seeing the better solution, well that's a question
how clever and skilled are you. ;-) I know I've still a long
way to go to reach the level of most of you (if I ever will).
But the pleasure of finding a solution myself comes first.
Thanks
@@i
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm