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: 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

One of my experiments was very short, and tantalisingly close to correct:

≠\V

Unfortunately, it's not quite right. Does anyone have an idea how to coerce that one into being right?

Regards,
Elias


On 20 March 2014 16:10, <address@hidden> wrote:
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]