# Overview

Run-length encoding — sequences in which the same data value occurs in many consecutive data elements are stored as a single data value and count

When using run-length encoding:

Input:  ABBBCCACB
Output: 1A3B2C1A1C1B


This sample has an output that is larger than the input.

Instead, it can be simplified for binary inputs by removing the data value in the result,

Input:  10001110101
Output: 1331111


which is significantly smaller. This works because, logically, if the there is a "next subset" then it must be of a different data value than the current subset. Since there are only two possible values (1 and 0), you always know the "next" data value subset.

# Challenge

Implement binary run-length encoding demonstrated above.

• Take input through STDIN or suitable alternative.

• Output to STDOUT or suitable alternative.

# Examples

In:  101011101011000011
Out: 11113111242

In:  01001010001
Out: 11211131

In:  000000000
Out: 9


You may assume that no subsets will be longer than 9 characters (there won't be 10 adjacent zeroes).

## marked as duplicate by Alex A. code-golf StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Dec 24 '15 at 23:52

• There is an error in your first example's output! The 1 digit after the first B shouldn't be there. – danmcardle Dec 23 '15 at 21:53
• @AlexA.: I don't see where conversion to binary will actually happen, and besides, I think that the shortest way to run-length encode a binary string will be appreciably different from regular run-length encoding. There might be some tricks or the like available w.r.t. binary that isn't there for other inputs. – El'endia Starman Dec 23 '15 at 22:00
• @El'endiaStarman Answers from the other challenge can be copied verbatim and be valid for this challenge, making this a duplicate. – Alex A. Dec 23 '15 at 22:56
• So it's not encoded whether the string starts with 0 or 1? – xnor Dec 24 '15 at 22:07
• For the purposes of this challenge, no. @xnor – Zach Gates Dec 24 '15 at 23:16

# Pyth - 5 bytes

hMrz8


# Stuck, 5 bytes

soT]y


Takes a binary string as input and outputs an array.

## Explanation

soT]y

s       get input string
o      run-level encoding
T     zip
]    flatten
y   pops the data values off


# Ruby, 37 29 bytes

->s{s.gsub(/0+|1+/){$&.size}}  Test: ->s{s.gsub(/0+|1+/){$&.size}}["10001110101"]
=> "1331111"