bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] How to zero every other 1 in a sequence


From: baruchel
Subject: Re: [Bug-apl] How to zero every other 1 in a sequence
Date: Thu, 20 Mar 2014 09:10:46 +0100
User-agent: Heirloom mailx 12.5 6/20/10

Elias Mårtenson <address@hidden> wrote:
> Assume I have a binary sequence. Say, something like this:
>
> 0 0 1 1 0 0 1 1 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 1
>
> Here, we can see a few sequences of consecutive ones. I want to zero out
> every second in each sequence. I.e, I'd like to get the following result:
>
> 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 1 0 1

Not sure if it is short enough, but this seems to work;
however I suggest you check it carefully:
  V×2|+\1⌈(⍳⍴V)×2|⊤\2+V


      V ← 0 0 1 1 0 0 1 1 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 1
      V×2|+\1⌈(⍳⍴V)×2|⊤\2+V
0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 1 0 1


Regards,

-- 
Thomas Baruchel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]