初级Beginner点子Idea
管道太慢:怎样用更少的 0 和 1
The Pipe Is Too Slow: Fewer 0s and 1s
常见的字母用短码,重复的像素只记“有几个”。预测得越准,就能压缩得越多。
Short codes for common letters, and just “how many” for repeated pixels. The better you predict, the more you can squeeze.
这是一个课程点子:活动和资料都有,学习单还没做。
This is a lesson idea: the activities and links are ready, the worksheets are not made yet.
每个字母都要 8 个 0 和 1,太慢了!能不能让常用的字母用短码、少用的字母用长码?
Every letter takes eight 0s and 1s. Too slow! Could common letters get short codes and rare letters long ones?
孩子做什么What kids do
- 数一数:拿一段英文(或一首儿歌的拼音),数每个字母出现了几次。Count: take some English text (or a nursery rhyme) and count how often each letter appears.
- 设计短码:最常见的给最短的码(摩斯电码里 E 只是一个“·”)。码之间没有空格,对方也得分得开。Design short codes: the most common letter gets the shortest code (in Morse code, E is a single dot). There are no gaps between codes, so they must still be easy to tell apart.
- 图片也能“瘦身”:“白白白白黑黑白白”可以写成“4 白 2 黑 2 白”。用这个方法压缩一张像素画。Pictures can slim down too: “white white white white black black white white” becomes “4 white, 2 black, 2 white”. Squeeze a pixel picture this way.
要点Key idea
常见的用短码、少见的用长码(哈夫曼编码);重复的东西只记“有几个”(游程编码)。照片、音乐、zip 文件都靠压缩。
Short codes for common things and long codes for rare ones (Huffman coding); for repeats, just write how many (run-length encoding). Photos, music and zip files all rely on compression.
和 AI 的关系Where AI comes in
如果你能猜到我下一个字,我就不用发给你了。压缩和语言模型其实是同一件事的两面。
If you can guess my next letter, I don’t need to send it. Compression and language models are two sides of the same thing.
视频与文章Videos and reading
- Tom Scott: How Computers Compress Text: Huffman Coding and Huffman Trees 7 分钟7 min
- CS Unplugged: Squeezing pictures into codes 图片压缩,不插电picture compression, unplugged
- Classic CS Unplugged: Text Compression 文字压缩text compression
- Crash Course CS #21: Compression 13 分钟,大孩子和老师13 min, older kids and teachers