Watch runs become a count and a symbol

Watch repeated letters, and rows of a picture, turn into a count and a symbol.

Theory Intermediate Compression · Text · Pictures ~6 min
The idea

Count a stretch, then write it once

A run is a stretch of the same symbol with no break. Run-length encoding stores the count and the symbol once for that stretch. The symbol is not stored again and again.

  1. Start at the left.
  2. Count how many times that symbol repeats before it changes.
  3. Write the count, then the symbol. The pair 5A means A, five times.
  4. Start the next run on the next symbol.

The picture uses the same rule, one row at a time. A new row starts a new run. Five A’s become 5A, which is two symbols instead of five. One A becomes 1A, which is two symbols instead of one, so the encoded text is longer.

TipYou can rebuild the original from the pairs. Write the symbol as many times as the count says. This page uses letters, and a picture of the letter I made from black and white squares.
DataThree examples
ExampleOriginalEncoded
RepeatedAAAAABBBCC
10 symbols
5A 3B 2C
6 symbols
MixedABCD
4 symbols
1A 1B 1C 1D
8 symbols
Picture8 by 4 squares
32 pixels
8 pairs
16 symbols

A count and a symbol are two symbols. A pixel is one symbol.

Interactive

Run the simulation

Look at the highlighted run, then at the pair that is written.

Step 0 / 0
Original and encodedrepeated letters
Ready
Shortcuts: Space play/pause · → step · ← back · R reset
Remember

A run, a pair, then a check

The same rule is used on letters and on each row of the picture.

1

A run

A run is the same symbol repeated with no break. A new letter, a new colour, or a new row ends it.

2

Count, then symbol

Each pair stores the count first, then the letter or the colour. Both of those count as symbols.

3

Not always shorter

Long runs use fewer symbols. A run of 1 still needs a count and a symbol, so the encoded form can be longer.