Similar, but exploiting Oblique instead of Suffix-Under-Reverse

           (# {. ([ * +)//. & (]"0 1/~)) 1 0 1 1 1 1 0 1
        1 0 1 2 3 4 0 1

I like this because I can watch the intermediate values flow from right to left.  
And I can stare at the result of  (]"0 1/~)  until I understand what Oblique 
means and how it relates to Prefix and Suffix.  Use only for pedagogical purposes: 
not recommended for large inputs because of the space and extra computation.

                        ... peter

On 10/22/14 07:44 PM, Marshall Lochbaum wrote:
Everything is reduce!

    ([*+)/\.&.|. 1 0 1 1 1 1 0 1
1 0 1 2 3 4 0 1

Marshall

On Wed, Oct 22, 2014 at 01:10:34PM -0400, Joe Bogner wrote:
This is probably easy but I can't figure it out. How can I count the number
of consecutive 1s?

Another way to think about it is a running sum that resets upon hitting a
zero

input=:1 0 1 1 1 1 0 1

expected=: 1 0 1 2 3 4 0 1
----------------------------------------------------------------------
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