I think you need f=: s Also, for what it's worth, here's another approach:
+/@(-~ >./\ <. >./\.) 0 5 3 5 1 2 3 In english: the height of fluid at any location depends on the walls surrounding it (highest on the left vs. highest on the right - whichever is lowest). Here's a more complicated example. I do not know if this was what you intended, but this was the kind of case which I considered while thinking about my approach: +/@(-~ >./\ <. >./\.) 3 0 4 0 5 0 2 9 In other words, here are our relevant left and right wall heights: >./\ 3 0 4 0 5 0 2 3 3 4 4 5 5 5 >./\. 3 0 4 0 5 0 2 5 5 5 5 5 2 2 and here is the water level that can result: (>./\ <. >./\.) 3 0 4 0 5 0 2 3 3 4 4 5 2 2 and, the resulting depths: (-~ >./\ <. >./\.) 3 0 4 0 5 0 2 0 3 0 4 0 2 0 Thanks, -- Raul On Wed, Oct 30, 2013 at 2:43 PM, inv2004 . <[email protected]> wrote: > Today I found one task, and of course decided to write it in J. > > Task: find volume: > > http://habr.habrastorage.org/post_images/0ca/4c0/046/0ca4c0046711fd9f8a743163a12f3c31.jpg > > > http://habr.habrastorage.org/post_images/539/fa1/294/539fa129413dc277e575798dc568337e.jpg > > My solution is: > <pre> > > w =: 0 5 3 5 1 2 NB. input > > s =: >./\ - [ NB. fun to calculate "holes" from L to R > > +/ (f w) <. f&.|. w NB. find "holes" L->R, find holes R->L. find > minimum for each, sum. > > </pre> > > > Q: standard: make it shorter. > > -- > Regards, > Alexander. > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
