Skip to main content
Codepiko
TR
All activities

To save a PDF, choose "Save as PDF" as the destination in the print window.

Text compression

The big idea

Texts repeat the same words and pieces again and again. Instead of writing a piece a second time, a computer leaves a short note: “go back this many letters and copy this many”. When it opens the text it follows the notes, and not a single letter is lost. The more a text repeats, the shorter it gets; with no repeats it does not shrink at all. It is the text cousin of “how many white, how many black” for pixels.

Where do we meet it?

ZIP files, PNG pictures and web pages that reach your phone faster all rely on this idea. Squeezed this way, the text of a novel takes up less than half the space. Photos and videos also shrink by throwing away tiny details your eye would not notice.

40 minutes in classFor teachers

  1. 5 minGetting attentionRepeat huntWrite “the train comes the train goes the train toots” on the board. Ask: “Is there a way to write this more briefly? Which pieces repeat?” Underline the repeats the pupils find.
  2. 12 minLessonBoxes on the boardWrite the sentence on the board with one letter in each square (a dot for a space). Volunteers stick a sticky note over a repeated piece and write something like “↶ 16, 10” on it. Another pupil opens the note: they go back 16 squares with a finger and read the 10 letters aloud. Count together how many letters were saved.
  3. 15 minLessonOn paper and on screenPairs fill in the “Write it short with boxes” sheet: one opens the code, the other finds the repeats, then they swap. Pairs who finish move on to the Squeeze the Text game.
  4. 8 minAssessmentWhich one shrinks?Write a rhyme and a row of random letters of the same length on the board. The class discusses which one will get shorter. Exit card: “Why is a ZIP file small? Why do random letters not get shorter?”

Codepiko · Computer science: Text compression

Write it short with boxes

Goal: Write repeated pieces as boxes that look back, and open a code made of boxes.

Time: 30 min · You need: Pencil; sticky notes for class play

Name:
Class:
Date:

1. Open the code

Some letters are not written; there are empty boxes in their place. “↶ 13, 7” above a box means: go back 13 letters and copy 7. Start counting back from the letter just left of the box; a space (·) counts as a letter too. Follow the arrows and fill in the empty boxes.

yellowchickfeathersayseep↶ 13, 7↶ 15, 8↶ 28, 6↶ 11, 3

2. Find the repeats

Find the pieces that were written before. Draw a box round each one, draw an arrow from the box to where the piece was first written, and write “how far back, how many letters” in the box. Then add up how many letters the boxes saved you from writing.

jamontoastjamonaspoonjamonmynose

Letters saved:

3. Think

Write a short answer.

Why can you not write random letters like “kej vux bip moz zul fad” more briefly?

codepiko.com