# How to Write a Quine: A Guide to Self-Replicating Code

> Hacker News story 49017054 · language: en · submitted 2026-07-23
> Web version: https://zeli.app/story/49017054
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 25 · by [mci](<https://news.ycombinator.com/user?id=mci>) · 💬 5
[original](<https://czterycztery.pl/slowo/quine-EN.html>) · [HN discussion](<https://news.ycombinator.com/item?id=49017054>)

## Summary

I explain the mechanics of a quine, a program that prints its own source code without introspection, using an allegory of a machine that builds copies of itself from a plan. I then walk through the step-by-step process of constructing a simple quine in Python, demonstrating how to insert a plan into a program to achieve self-replication.

## Key quote

> This whole story about the machine is not an independent puzzle; it doesn't even have to make perfect sense, it only serves to help you understand better why the quine I'll write in a moment is built the way it is and how it works.

## HN discussion (5 comments)

### [thomascountz](<https://news.ycombinator.com/item?id=49044481>)

> I learned something and along the way, I really enjoyed the author's writing style!
>
> Phew, it works. But it wasn’t easy, was it? That’s why remember my advice: when writing a quine, avoid using quotes. Once you start escaping them, you’ll never get out to go sledding. At this point, I stop writing the text and go sledding.

### [firasd](<https://news.ycombinator.com/item?id=49042867>)

> The idea in all the examples in this page seems to be: write a string with some code and then write some more code that processes the string in a way that when the string is finally output it contains the variable assignment (of the string), the variable contents, and the later program code.
>
> Indeed that is what the first wikipedia example does
>
> a = 'a = {}{}{}; print(a.format(chr(39), a, chr(39)))'; print(a.format(chr(39), a, chr(39)))
>
> I dunno, my explanation seems to make more sense in my head than the analogy this article fixates on of a machine that can build a machine etc

### [erikschoster](<https://news.ycombinator.com/item?id=49043093>)

> My bandmate made our site a quine at one point: https://web.archive.org/web/20161129032158/http://nasa.pink/
>
> Today I suppose this would get clobbered by bots but in 2016 it was fun and I still am in awe of how simple he made it.

---

## Cite

- Page: https://zeli.app/story/49017054
- Date: 2026-07-23
- Source: czterycztery.pl (https://czterycztery.pl/slowo/quine-EN.html)
- Hacker News: https://news.ycombinator.com/item?id=49017054

## Other languages

- zh: https://zeli.app/zh/story/49017054 · markdown: https://zeli.app/zh/story/49017054.md
- ja: https://zeli.app/ja/story/49017054 · markdown: https://zeli.app/ja/story/49017054.md
- ko: https://zeli.app/ko/story/49017054 · markdown: https://zeli.app/ko/story/49017054.md
- de: https://zeli.app/de/story/49017054 · markdown: https://zeli.app/de/story/49017054.md
- es: https://zeli.app/es/story/49017054 · markdown: https://zeli.app/es/story/49017054.md
