编程与软件工程preshing.com
用混淆 Python 生成高分辨率曼德博集合
High-Resolution Mandelbrot in Obfuscated Python
2011 — 2018,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这篇文章展示了一段混淆后的 Python 代码,运行数小时即可渲染出高分辨率的 Mandelbrot 分形图,且图片中直接包含生成它自己的源代码。作者在 Python 这种对缩进和空白敏感的语言里实现了代码混淆,颇具巧思。
为什么经久不衰:它把代码混淆、分形数学和'自生成图像'的趣味结合在一起,多年来反复登上 HN 首页,至今仍是展示 Python 可玩性的经典小作品。
HN 评论精选
在 Python 这种对空白敏感的语言里做混淆尤其难得
最让我印象深刻的是,这一切是在一门空白符(缩进)真正有语法意义的语言里实现的。
erkmene查看英文原文
The fact that this is accomplished in a language where whitespace really matters impressed me the most.
像素可独立计算,适合并行渲染加速
Mandelbrot 集的一个好处是每个像素都可以独立计算,也就是说有 8 个 CPU 就可以把图分成 8 份并行渲染。我四年前试过,结果在这里:https://gist.github.com/jrockway/291074,不过还是很慢,得放到公司的机器上跑。
jrockway查看英文原文
One thing that's nice about the Mandelbrot set is that you can calculate each pixel independently of all the other pixels. This means if you have 8 CPUs, you can split the image into 8 parts and render it that way. I apparently decided to try this out about 4 years ago. Here's the result: https://gist.github.com/jrockway/291074 Still slow. Need to run this on some machines at work :)
分享降低分辨率运行的实用技巧
也可以做低分辨率版本。我用 x=1024, 800 并在 800 前加空格伪造 4 的倍数宽度,运行成功。我很喜欢这种混淆手法,向作者致敬。
clebio查看英文原文
> If you’re willing to leave the script running for a few hours, you can increase the image resolution on line 8. (Just make sure the width is divisible by 4.) You can make a lower resolution version too. I used: ) ;v, x=1024, 800;C=range(v*x which fakes the 4-width with a space before 800, and it worked fine: http://i.imgur.com/c9ossnw.png I like this use of obfuscation a lot. Kudos to the author. (EDIT: Code format)
代码具有美感,值得像艺术品一样被展出
有点跑题,但博客的结论让我想到:会不会有一天有人把代码放进博物馆展出?见过真正顶级代码的人都知道正确的代码有一种美感,为什么不装裱起来展览呢?数学或物理公式也可以,但它们太短且含义晦涩,而代码至少部分用人类语言写成,观众还能看懂。
bsaul查看英文原文
A bit of topic, but the blog conclusion made me wondered if anyone would one day expose code in a museum. Any people who've seen real top level code know there is a kind of beauty or at least aesthetic in very correct code, so why not put them on a frame and expose them. Same could be said of some really important mathematic or physic formulas, but they're sometimes short and their meaning really is obscure. Whereas code is at least partially written in human language, which would make such an exhibit still understandable by everyone.
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选