Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Quines (Self-Replicating Programs) (madore.org)
66 points by lifthrasiir on Jan 11, 2022 | hide | past | favorite | 20 comments


Quines also play a large part in the Reflections on Trusting Trust essay

https://www.cs.cmu.edu/~rdriley/487/papers/Thompson_1984_Ref...


The most amazing multi-quine I've seen is the quine relay here: https://github.com/mame/quine-relay

It goes through 128 programming languages to regen its starting point.


Fun 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).


This is the first project I've ever seen with an excuse to declare as many dependencies as it does.


There is an issue on Nixpkgs to package this absolute (but beautiful) monster of a package.[0]

[0] https://github.com/NixOS/nixpkgs/issues/131492


Interesting 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.


> 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.


Source code inspection (or cp) is considered cheating for quines, normal viruses don't follow this rule


Cool! I will have a look.

BTW this was raised in a cracking corecursive episode recently https://corecursive.com/quines-polyglot-code/


An interesting "application" are zip quines, where a compressed archive decompresses to itself. 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.


Joy 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]


Is a forkbomb also a Quine(s)? I love this famous one from Dyne.org[1]: :(){ :|:& };:

[1] https://jaromil.dyne.org/journal/forkbomb_art.html


Anyone interested in this should really read Hoffstadter's Gödel, Escher, Bach.


```

#!/bin/bash

cat $0

```


Wouldn'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.


Or as was posted to 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


or just an empty string for various languages


Seems 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.


I think they meant that the program would be 0 bytes long, not two characters which are both quotation marks


Ah, I see. Funny lateral thinking exercise I guess, not so interesting in terms of actually creating a Quine :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: