4 ms·
Quines (Self-Replicating Programs)
- nathias 5y agoAnyone interested in this should really read Hoffstadter's Gödel, Escher, Bach.
- carapace 5y agoJoy lang has a particularly beautiful quine: [[dup cons] dup cons] You run it with the i combinator: [[dup cons] dup cons] i [dup cons] dup cons [dup cons] [dup cons] cons [[dup cons] dup cons]
- Normille 5y agoInteresting article. I'd never heard of this concept before and thought "That sounds trivial" until I started to read the article. I must admit though, I gave up halfway through when the C code got too esoteric for me to follow. But still feel I've learned something new today. The article title seems a bit off though. When I read 'Self-Replicating Programs' [sic] it I immediately thought "Worms" but the article actually refers to programmes which can print out their own source code listing. Which seems to me to be a different challenge.
- credit_guy 5y ago> When I read 'Self-Replicating Programs' [sic] it I immediately thought "Worms" You are not wrong at all. At its base, any virus is a quine. Well, both computer viruses and biological viruses are quines. Life itself would not be possible without quines.
- cuteboy19 5y agoSource code inspection (or cp) is considered cheating for quines, normal viruses don't follow this rule
- darkwater 5y ago``` #!/bin/bash cat $0 ```
- susam 5y agoOr as was posted to https://news.ycombinator.com/item?id=29874052 https://news.ycombinator.com/item?id=29874052 by @jcalvinowens a few hours ago, we can also simplify this to just: #!/bin/cat Example: $ echo '#!/bin/cat' > foo $ chmod +x foo $ cat foo #!/bin/cat $ ./foo #!/bin/cat
- charcircuit 5y agoor just an empty string for various languages
- capableweb 5y agoSeems like that would only work for languages where the last returned value is printed as-is when running it. Other languages wouldn't print `""` but have no output instead.
- drdeca 5y agoI think they meant that the program would be 0 bytes long, not two characters which are both quotation marks
- capableweb 5y agoAh, I see. Funny lateral thinking exercise I guess, not so interesting in terms of actually creating a Quine :)
- capableweb 5y agoWouldn't this be considered cheating according to the submission? > The easiest way to do that, of course, is to seek the source file on the disk, open it, and print its contents. That may be done, but it is considered cheating; besides, the program might not know where the source file is, it may have access to only the compiled data, or the programming language may simply forbid that sort of operations.
- 2wrist 5y agoCool! I will have a look. BTW this was raised in a cracking corecursive episode recently https://corecursive.com/quines-polyglot-code/ https://corecursive.com/quines-polyglot-code/
- dwheeler 5y agoThe most amazing multi-quine I've seen is the quine relay here: https://github.com/mame/quine-relay https://github.com/mame/quine-relay It goes through 128 programming languages to regen its starting point.
- yalue 5y agoFun side fact: that's a project from Yusuke Endoh, who also happens to be the most prolific winner of the the obfuscated C contest (ioccc.org).
- siraben 5y agoThere is an issue on Nixpkgs to package this absolute (but beautiful) monster of a package.[0] [0] https://github.com/NixOS/nixpkgs/issues/131492 https://github.com/NixOS/nixpkgs/issues/131492
- commandlinefan 5y agoThis is the first project I've ever seen with an excuse to declare as many dependencies as it does.
- yorwba 5y agoAn interesting "application" are zip quines, where a compressed archive decompresses to itself. https://research.swtch.com/zip https://research.swtch.com/zip I recently built a zip quine that was simultaneously a valid PDF to show off, and the most fun part was making the CRC32 check succeed. If the checksum had been based on a cryptographic hash function, it would've been essentially impossible, but fortunately CRC32 can be reversed simply by solving a system of linear equations.
- vsnf 5y agoQuines also play a large part in the Reflections on Trusting Trust essay https://www.cs.cmu.edu/~rdriley/487/papers/Thompson_1984_ReflectionsonTrustingTrust.pdf https://www.cs.cmu.edu/~rdriley/487/papers/Thompson_1984_Ref...
- thenthenthen 5y agoIs a forkbomb also a Quine(s)? I love this famous one from Dyne.org[1]: :(){ :|:& };: [1] https://jaromil.dyne.org/journal/forkbomb_art.html https://jaromil.dyne.org/journal/forkbomb_art.html