你能用不到 500 字节构建一张可辨识的世界地图吗?
Can you build a recognizable World Map in under 500 bytes?

原始链接: https://www.experimentlog.com/blog/building-a-world-map-with-only-500-bytes

几年前,作者曾为 JS1k 比赛成功制作了一个小于 1KB 的世界地图,最近他重温这一挑战,尝试利用生成式人工智能(GenAI)来优化结果。通过使用 Codex,作者发现尽管 AI 在处理 SVG 路径复杂度和空间识别上存在困难,但在迭代 ASCII 表示形式方面却很有帮助。 此次突破不仅在于简化地图,更在于选择了针对压缩优化的格式。通过去除空白边缘和水印,作者发现“填充式”的陆地形状——包含长而可预测的重复字符——比稀疏的轮廓线压缩效果更好。通过对纯陆地的 ASCII 地图应用 `deflate-raw` 算法,作者将地图数据压缩到了仅 445 字节。加上必要的 base64 数据和解压逻辑,整个项目依然远低于 1KB 的限制。 作者目前正向其他人发起挑战,欢迎大家超越这一效率,或创作出更逼真的 1KB 世界地图。

最近的一则 Hacker News 讨论帖探讨了一个挑战:如何用不到 500 字节的代码绘制出一张可辨识的世界地图。这次讨论源于一项实验,即通过 `fetch()` 和 `data:` URI 将压缩数据流直接加载到浏览器中。 讨论很快扩展到对高效数据表示的更广泛技术探索。用户们讨论了以下内容: * **算法压缩:** 探讨了针对特定指令集定制的压缩算法是否能优于通用解码器,并触及了柯尔莫哥洛夫复杂性(Kolmogorov complexity)的理论极限。 * **优化策略:** 建议包括使用位级存储(因为地图仅由陆地/水域组成)、利用傅里叶级数等参数函数进行程序化生成,以及使用 PNG 等图像格式来利用空间冗余。 * **准确性:** 参与者评价了地图的地理细节(例如特定湖泊的位置),突显了微优化与视觉保真度之间的权衡。 总的来说,该讨论帖反映了开发者社区对极致代码高尔夫(code golf)以及数据压缩理论与创意编程相结合的持续热衷。
相关文章

原文
World Map with only 500 bytes

A little over 10 years ago, I entered a JS1k compeition and built a small jsfiddle clone in under 1k. A few years later, I joined the competiton again to see if it was possible to build a World Map in under 1k. My approach was to render the world as ASCII inside a <pre> tag and use tiny characters for land and water. It worked, but lately I wanted to see if we can go even smaller in size, perhaps with the help of GenAI.

I have been doing a lot with Claude Code so for this I wanted to try Codex and I was surprised that AI did not perform very well. Codex considered a variety of approaches, starting with SVG which failed because 500 bytes seems not enough to draw anything recognizable. A real-looking world map is mostly coastline detail, and SVG/canvas paths have to pay for every coordinate. Once the shapes were simplified enough to be small, they stopped looking like the world.

Eventually, Codex landed back on ASCII format but it did not recommend further improvements like removing anything that did not help recognition. I suggested that water dots could be removed, the empty left margin was cropped, and the map was reduced to land-only * characters inside a tighter bounding box. We tested removing the filled interiors and keeping only continent outlines, but that actually compressed worse. Filled land creates long predictable runs of repeated characters, and compression loves repeated runs more than sparse outlines with lots of little gaps.

The final compression step used deflate-raw on the land-only cropped map. The visible map text was still 8,523 bytes uncompressed, but the compressed map data dropped to 445 bytes. I think that was the highlight, not drawing a less detailed map but choosing a representation that compression can exploit. The HTML is larger (still under 1k) because it needs base64 data plus browser decompression code, but the map itself is under 500 bytes.

You can check it out here and this is the repo. Now, can someone beat this with a different approach (not just removing a few characters) or generate a 1k version that is more realistic?

联系我们 contact @ memedata.com