|
From: | Elias Mårtenson |
Subject: | Re: [Bug-apl] How to zero every other 1 in a sequence |
Date: | Fri, 21 Mar 2014 00:23:41 +0800 |
≠\V
Elias Mårtenson <address@hidden> wrote:Not sure if it is short enough, but this seems to work;
> 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
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 1Regards,
--
Thomas Baruchel
[Prev in Thread] | Current Thread | [Next in Thread] |