# Halve the falses

Given a non-empty array of 0 and 1, halve the lengths of the runs of 0.

# Input

An array of 0 and 1. Acceptable format:

• Real array in your language
• Linefeed-separated string of 0 and 1
• Contiguous string of 0 and 1
• Any other reasonable format

For example, the following three inputs are all acceptable:

• [1, 0, 0, 1]
• "1\n0\n0\n1" (where \n is a linefeed U+000A)
• "1001"

You may assume that the runs of 0 will have even length.

# Output

An array of 0 and 1, in the acceptable formats above.

# Testcases

input ↦ output
[1,0,0,1,0,0,1] ↦ [1,0,1,0,1]
[1,1,0,0,1,1,0,0,1] ↦ [1,1,0,1,1,0,1]
[1,1,0,0,1,1,1,0,0,1,1] ↦ [1,1,0,1,1,1,0,1,1]
[1,1,1] ↦ [1,1,1]
[0,0,1] ↦ [0,1]
[0,0] ↦ [0]
[1,1,1,0,0,0,0,1,1,1,1,0,0,1,0,0,1,1,0,0,1,1,1,1,0,0,1,0,0] ↦ [1,1,1,0,0,1,1,1,1,0,1,0,1,1,0,1,1,1,1,0,1,0]


# Scoring

This is . Shortest answer in bytes wins.

Standard loopholes apply.

• In the last testcase, don't the runs of zeroes not have even length? Commented May 3, 2017 at 11:26
• @OldBunny2800 Read the test case carefully; the 0-runs have lengths 4, 2, 2, 2, 2, and 2. Commented May 3, 2017 at 12:21
• Can we take true and false instead of 1 and 0? Commented May 3, 2017 at 18:13
• @Cyoce which language? Commented May 3, 2017 at 18:15
• @LeakyNun Ruby, which considers 0 to be truthy. Commented May 3, 2017 at 18:16

# brainfuck, 23 bytes

,[.++[->+++++<]>+[,>],]


Try it online!

,[         while(c=getchar()) {
.++[       putchar(c);
->+++++< e=5*(c+2)
]
>+[        if(e!=-1) {
,>         getchar();
]          }
,]         }


# Desmos, 28 bytes

f(L)=L[(L-1)^{[0...9999]}<1]


Takes input as a list of 0s and 1s, and returns a list of 0s and 1s.

This works by filtering for elements that are either 1, or 0 and with odd (0-based) index in the list.

Desmos lists have a maximum length of 10000 elements, so [0...9999] is a valid golf from [0...L.length].

Try it on Desmos!

# AWK, 8 bytes

$0||NR%2  Try it online! I found this nice solution following the thinking of this answer. It's a simple OR gate used as a AWK pattern: it prints the line if the input is true (i.e., 1) or it's an odd line (NR is the number of the line). It will skip only the 0 in even lines. ### AWK, 15 bytes (former answer) gsub("00","0")1  Try it online! Globally substitutes all "00" strings to "0". The 1 in the end is a True token to force printing the line if there were no substitutions. # Julia, 21 bytes !x=replace(x,"00"=>0) Attempt This Online! # Wolfram Language (Mathematica), 22 bytes Select[#>=(i=-i)&] i=1  Try it online! # Octave, 25 bytes @(a)a(~mod(cumsum(~a),2))  Try it online! Find the indices of even elements in the cumsum of the logical negation of the input. # Uiua, 4 bytes ▽\=.  Try it! Port of emanresu A's Vyxal answer. ▽\=. . # duplicate \= # scan by equality ▽ # keep  # Perl 5 50 + 1 (for -p flag) = 51 bytes @a=split'',$_;splice@a,$i++,!$_ for@a;\$_=join'',@a