[Question]
  [
# Task
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 [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). Shortest answer in bytes wins.
[Standard loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) apply.
  
[Answer]
## [Retina](https://github.com/m-ender/retina), 4 bytes
```
00
0
```
[Try it online!](https://tio.run/nexus/retina#@29gwGXw/7@hoaEBEBiCaRAyROIAAA "Retina – TIO Nexus")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes
```
00¤.:
```
[Try it online!](https://tio.run/nexus/05ab1e#@29gcGiJntX//4aGhgZAYAimQcgQiQMA "05AB1E – TIO Nexus")
**Explanation**
```
00     # push 00
  ¤    # tail, pushes 0
   .:  # replace
```
[Answer]
# [Haskell](https://www.haskell.org/), 33 bytes
```
f(0:0:r)=0:f r
f(x:r)=x:f r
f e=e
```
[Try it online!](https://tio.run/nexus/haskell#@5@mYWBlYFWkaWtglaZQxJWmUQHiVEA4Cqm2qf9zEzPzFGwVCooy80oUVBTSFKINdUDQAAoNdRB8Q7gIVpnY/wA "Haskell – TIO Nexus") Usage: `f[1,1,0,0,1,1,0,0,1]`. Iterates over the list and replaces two consecutive zeros by one zero.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 35 bytes
```
f(char*s){while(*s)putchar(*s),*s++-48?:s++;}
```
48 is the ascii code of '0'
better version 43 bytes as suggested by Neil
```
f(char*s){while(*s)putchar(*s),s+=2-*s%2;}
```
another one 40 byte this time (again as suggested by Neil & VisualMelon) :)
```
f(char*s){for(;*s;s+=50-*s)putchar(*s);}
```
and then 35 bytes thanks to Khaled.K 
```
f(char*s){*s&&f(s+50-putchar(*s));}
```
[Try it online!](https://tio.run/nexus/c-gcc#@5@mkZyRWKRVrFmtVaymlqZRrG1qoFtQWgIS1QAKa1rX/s/MK1HITczM09DkquZSSNNQMjAwBCIgADNAwDDGQEnTmqv2PwA "C (gcc) – TIO Nexus")
[Answer]
# [sed](https://www.gnu.org/software/sed/), 8 bytes
```
s/00/0/g
```
[Try it online!](https://tio.run/nexus/sed#@1@sb2Cgb6Cf/v@/oYEBCHEZgkgkFpgAsg25QGIGBgA "sed – TIO Nexus")
[Answer]
# Octave, 22 bytes
```
@(s)strrep(s,'00','0')
```
[**Verify all test cases here.**](https://tio.run/#TAaXw)
This is an anonymous function taking a string on the format `'1001000011'` as input, and replaces two consecutive zeros with a single zero.
[Answer]
# [Haskell](https://www.haskell.org/), 28 bytes
```
f(h:t)=h:f(drop(1-h)t)
f e=e
```
[Try it online!](https://tio.run/nexus/haskell#@5@mkWFVommbYZWmkVKUX6BhqJuhWaLJlaaQapv6PzOvoLSkWMFWITraUMcACKFkrA6QDxPBLgZnQcVBNEwdkIaJglUh9KDYgmIakkxsLBdXbmJmHtBdBUWZeSUKKgq5iQUKaQoQ5/4HAA "Haskell – TIO Nexus")
Recursively takes the first element, dropping the second one if the first one is zero, until the list of empty. If the first entry is `h`, then the first `1-h` are dropped from the remainder. 
[Answer]
# Java, 50 bytes
```
String f(String s){return s.replaceAll("00","0");}
```
[**Try Online**](http://ideone.com/2lMKHM)
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~7 6~~ 5 bytes
```
d'0²0
```
[Try it online!](https://tio.run/nexus/japt#@5@ibnBok8H//0qGBgYgpAQA "Japt – TIO Nexus")
Simply replaces each run of two zeroes in the input by one zero. Uses string input (i.e. `"1001001"`).
[Answer]
# [Husk](https://github.com/barbuz/Husk), 4 bytes
```
fG=¹
```
[Try it online!](https://tio.run/##yygtzv6f@6ip8X@au@2hnf///4@ONtQxAEIoGasD5MNEsIvBWVBxEA1TB6RhomBVCD0otqCYhiQTGwsA "Husk – Try It Online")
**How?**  
The [Husk](https://github.com/barbuz/Husk) `scanl` command (`G`) applies a function to each element of a list and the result-so-far. The initial result-so-far is set to the first element.
In this case, used with the `eq` (`=`) function, it checks whether each element is equal to the result-so-far. For runs of `1`, this will always output `1` (truthy). Now, the first of any run of `0`s will be `0` (falsy), of course; then, the next result will be `1` (since `0` is equal to the result-so-far), and then `0`, and so on, alternating `0`s at odd positions in the run and `1`s at even positions, until the end of the run. Since there are always an even number of `0`s in each run, then last result-so-far must be `1`: so, when we enter the next run of `1`s, the first result will be `1` (truthy) again, and so on...
So: runs of `0`s get alternating `0` and `1`, and runs of `1`s always get `1`, and we just need to `filter` (`f`) the input list (`¹`) by this.
[Answer]
## [Alice](https://github.com/m-ender/alice), 13 bytes
```
/oe00/
@iS0e\
```
[Try it online!](https://tio.run/nexus/alice#@6@fn2pgoM/lkBlskBrz/7@hoaEBEBiCaRAyROIAAA "Alice – TIO Nexus")
### Explanation
```
/.../
@...\
```
This is a simple template for linear programs which operate entirely in Ordinal mode. The initial `/` reflects the IP to move south east and then it bounces diagonally up and down through the code until the mirrors at the end. Those simply offset the position by one so that on the way back the IP traverses the remaining cells. Reading the code in this zigzag fashion it becomes:
```
ie00e0So@
```
This is a simple string substitution:
```
i   Read all input.
e   Push an empty string.
00  Append two zeros to create the string "00".
e   Push an empty string.
0   Append a zero to create the string "0".
S   Substitute all occurrences of "00" in the input with "0".
o   Output the result.   
@   Terminate the program.
```
There are a few other ways to push the two strings, e.g. `'00'0` or `e000t`, but I haven't found anything that beats 5 bytes there (and I'd have to shave off two bytes to be able to shorten the program).
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
ṣ1j1,1m2
```
[Try it online!](https://tio.run/nexus/jelly#@/9w52LDLEMdw1yj////A2kgNIBCQx0E3xAuglUGAA "Jelly – TIO Nexus")
Possibly other answers in languages without a `.replace()` or similar could use this trick.
**Explanation**
```
ṣ1j1,1m2 - (duplicates the 1s, then halves all lengths)
ṣ1       - split by the element 1
  j1,1   - join the elements with the two-element list 1,1
      m2 - get every second element
```
[Answer]
# Perl 5, 7+1(-p flag)=8 bytes
```
<>if/0/
```
Takes input as newline separated numbers. Skips the next line if it sees a zero.
[Answer]
# [V](https://github.com/DJMcMayhem/V), 4 bytes
```
òf0x
```
[Try it online!](https://tio.run/nexus/v#@394U5pBxf//BkBgCAQwEsGHAAA "V – TIO Nexus")
```
ò    ' Recursively (until we error)
 f0  ' Go to the next zero (errors when there are no zeros left)
   x ' Delete it
```
[Answer]
# [sed](https://www.gnu.org/software/sed/), ~~8~~ 6 bytes
```
n;/0/d
```
[Try it online!](https://tio.run/##K05N0U3PK/3/P89a30A/5f9/Ay4DLkMwNIBCw3/5BSWZ@XnF//VTUsv0i0tSMvMA "sed – Try It Online")
Takes a linefeed-separated string of `0` and `1`.
`n` skips a line, and `/0/d` deletes a line if it has a zero in it. This has the net effect of deleting every `0` on an even-numbered line. Since any even-length contiguous list of `0` has the same number of even-numbered and odd-numbered lines, this has the effect of halving the length of every run of `0`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
¹‘ƭƇ
```
[Try it online!](https://tio.run/##y0rNyan8///QzkcNM46tPdb@/3D7o6Y1kf//R3NFG@oYACGUjNUBCcCEcAjCWTAJMAOuFMiAS4BVIvSh2IViIpIMUHMsAA "Jelly – Try It Online")
## Explanation
```
¹‘ƭƇ   Main monadic link
   Ƈ   Filter by
  ƭ      Every time this is called, switch between
¹          doing nothing and
 ‘         adding 1
```
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), 42 bytes
```
[0,0|T]*[0|R]:-T*R.
[H|T]*[H|R]:-T*R.
H*H.
```
[Try it online!](https://tio.run/nexus/prolog-swi#@x9toGNQExKrFW1QExRrpRuiFaTHFe0BFvFAiHhoeej9/x9tqAOCBlBoqIPgG8JFsMrEakXocZUXZZakakRoAgA "Prolog (SWI) – TIO Nexus")
[Answer]
# PHP, 26
```
<?=strtr($argn,["00"=>0]);
```
simply replace all `00` by `0`.
[Answer]
# Lua, 33 bytes
```
print((io.read():gsub("00","0")))
```
Takes a string via input and condenses double zeros. Easy.
[Answer]
# [MATL](https://github.com/lmendo/MATL), 5 bytes
```
FFOZt
```
[**Try it online!**](https://tio.run/nexus/matl#@@/m5h9V8v9/tKGOARBCyVgA)
### Explanation
This is similar to Stewie Griffin's [Octave answer](https://codegolf.stackexchange.com/a/118609/36398):
```
FF     % Push [0 0]
O      % Push 0
Zt     % Implicitly take input. Replace [0 0] by 0. Implicitly display
```
---
# 8 bytes
```
vy~f2L)(
```
This avoids the string/array replacement builtin.
[**Try it online!**](https://tio.run/nexus/matl#@19WWZdm5KOp8f9/tKGOARBCyVgA)
### Explanation
Consider input `[1,0,0,1,0,0,1]` as an example:
```
v      % Concatenate stack (which is empty): pushes []
       % STACK: []
y      % Implicit input. Duplicate from below
       % STACK: [1,0,0,1,0,0,1], [], [1,0,0,1,0,0,1]
~f     % Negate, find: gives indices of zeros
       % STACK: [1,0,0,1,0,0,1], [], [2,3,5,6]
2L     % Push [2,2,1i]. As an index, this is interpreted as 2:2:end
       % STACK: [1,0,0,1,0,0,1], [], [2,3,5,6], [2,2,1i]
)      % Reference indexing. This selects the even-indexed entries
       % STACK: [1,0,0,1,0,0,1], [], [3,6]
(      % Assignment indexing. This deletes the specified entries
       % (assigns them the empty array). Implicitly display
       % STACK: [1,0,1,0,1]
```
[Answer]
# [Alice](https://github.com/m-ender/alice), ~~12~~ 10 bytes
*2 bytes saved thanks to [Martin Ender](https://codegolf.stackexchange.com/users/8478/martin-ender)*
```
i.h%.7%$io
```
[Try it online!](https://tio.run/nexus/alice#@5@pl6GqZ66qkpn//7@hoaEBEBiCaRAyROIAAA "Alice – TIO Nexus")
### Explanation
This is a 1-D code operating in cardinal mode, so it's easy to follow its flow:
```
i                   Read a byte from input (pushes -1 on EOF)
 .h                 Duplicate it and add 1 to the copy
   %                Compute n%(n+1). This will exit with an error on n==-1
                    and return n for any non-negative n.
    .7%             Duplicate the input again and compute its value modulo 7
                    This returns 6 for '0' (unicode value 48) and 0 for '1'
                    (unicode value 49)
       $i           If this last result was not 0, input another number.
                    This ignores every other '0' in the input
                    and moves to the following number (another '0')
         o          Output the last byte read
                    At the end, wrap back to the beginning of the line
```
[Answer]
# [Java](http://openjdk.java.net/), ~~131~~ 123 bytes
```
int[]f(int[]a){int c=0,i=0,l=a.length;for(int x:a)c+=1-x;int[]r=new int[l-c/2];for(c=0;c<l;c+=2-a[c])r[i++]=a[c];return r;}
```
[Try it online!](https://tio.run/nexus/java-openjdk#bY89bsMwDIV3n0KjBNtqnLGqhh6gU0ZDA6vargpFNig6TWD47K7k9GcpCOFR5HvAx2l@9c4y6yFG9gIuLJsL1Jqe7wJiScqsPlQuPa9B@i4M9K76EbOFXR9B2FI39VXtCdSh@2S59bV9OJrdmPLKPnmVjMcaWmsEtq4sjc69wo5mDAzVuk13nEhASS6je2PnBMVPhC4MiQeHKJbidIvUneU4k5zSgnzgH3ABOZPz8hkRblHSeA/xzJMv40L2/AfOLE2V6/BdTfX3b34n/25WIYQq1mLdvgA "Java (OpenJDK 8) – TIO Nexus")
[Answer]
# JavaScript (ES6), ~~26~~ 21 bytes
Takes the input as a string and returns a string.
```
s=>s.replace(/00/g,0)
```
---
## Try It
```
f=
s=>s.replace(/00/g,0)
i.addEventListener("input",_=>o.innerText=f(i.value))
console.log(f("1001001")) // "10101"
console.log(f("110011001")) // "1101101"
console.log(f("11001110011")) // "110111011"
console.log(f("111")) // "111"
console.log(f("001")) // "01"
console.log(f("00")) // "0"
console.log(f("11100001111001001100111100100")) // "1110011110101101111010"
```
```
<input id=i><pre id=o>
```
[Answer]
# Mathematica, 24 bytes
```
StringReplace["00"->"0"]
```
A function that expects a string of `"0"`s and `"1"`s and returns a similar string. Self-explanatory syntax. Mathematica has lots of transformation builtins; the key is to use one that transforms every relevant subexpression (unlike `/.`) but only passes through the expression once (unlike `//.`).
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 5 bytes
```
aR00i
```
Takes a string of 0s and 1s. [Try it online!](https://tio.run/##K8gs@P8/McjAIPP///@GhoYGQGAIpkHIEIkDAA "Pip – Try It Online")
### Explanation
Beating Jelly? Inconceivable!
```
a      Take the first command-line argument
 R     and replace
  00   00 (an integer literal, so it doesn't need quotes)
    i  with i (variable preinitialized to 0)
       Autoprint
```
[Answer]
# [R](https://www.r-project.org/), 21 bytes
```
function(n)n[n+1:0>0]
```
[Try it online!](https://tio.run/##K/qfpmCj@z@tNC@5JDM/TyNPMy86T9vQysDOIPZ/mkayhqGOARAaamr@BwA "R – Try It Online")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 4 bytes
```
ɖ=Tİ
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=2#WyIiLCIiLCLJlj1UxLAiLCIiLCJbMSwxLDAsMCwxLDEsMSwwLDAsMCwwLDEsMCwwLDFdIl0=) Port of [Dominic van Essen's Husk answer](https://codegolf.stackexchange.com/a/241062/100664). See that for a more detailed explanation of how this works.
```
ɖ    # Scan by
 =   # Equal to the current result?
     # For runs of 1s, this is 1,
     # For runs of 0s this alternates between 1 and 0
  Tİ # Keep only items wihtt a 1 in the previous list
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 10 bytes
```
ḅ{cẹ|ḍh}ᵐc
```
[Try it online!](https://tio.run/nexus/brachylog2#@/9wR2t18sNdO2se7ujNqH24dULy///RhjqGOgZACKdj/0cBAA "Brachylog – TIO Nexus")
Not sure this is optimal yet…
### Explanation
This exploits the bug that `c` on a list of integers that has leading zeroes will fail.
```
ḅ               Blocks; group consecutive equal elements together
 {     }ᵐ       Map on each block:
  c               It is possible to concatenate the block into an int (i.e. it contains 1s)
   ẹ              Split it again into a list of 1s
    |             Else
     ḍh           Dichotomize and take the head
         c      Concatenate the blocks into a single list
```
[Answer]
# [Python](https://docs.python.org/2/) (list I/O), 36 bytes
```
f=lambda l:l and l[:1]+f(l[2-l[0]:])
```
[Try it online!](https://tio.run/nexus/python2#@59mm5OYm5SSqJBjlaOQmJeikBNtZRirnaaRE22kmxNtEGsVq/k/Lb9IIUchMy/aUMcACKFkrA6QDxPBLgZnQcVBNEwdkIaJglUh9KDYgmIakkysFRdnQVFmXokC0K2a/wE "Python 2 – TIO Nexus")
Recursively takes the first element, then removes the remaining one if the first one was zero.
---
**38 bytes:**
```
lambda l:eval(`l`.replace('0, 0','0'))
```
[Try it online](https://tio.run/nexus/python2#S7ON@Z@TmJuUkqiQY5ValpijkZCToFeUWpCTmJyqoW6go2CgrqNuoK6p@T8tv0ghRyEzL9pQxwAIoWSsDpAPE8EuBmdBxUE0TB2QhomCVSH0oNiCYhqSTKwVF2dBUWZeiUKaRo7mfwA "Python 2 – TIO Nexus") This takes a Python list and outputs a Python list by doing replacement on its string representation. String I/O would allow a more direct and shorter solution, such as
```
lambda s:s.replace('00','0')
```
for `'1001'` format.
[Answer]
# [///](https://esolangs.org/wiki////), 11 bytes
```
/00/a//a/0/<input goes here>
```
[Try it online!](https://tio.run/nexus/slashes#@69vYKCfqA9EBvr//wMA "/// – TIO Nexus")
Fun fact: `/00/0/<input>` won't work, because it reduces `0000` to `0`. Hence the `a`-substitute. 
]