

The world's smallest self-replicating program - ismailmechbal
http://www.ioccc.org/1994/smr.hint

======
corwinbad
phiX174 virus - one of the world's smallest self-replicating programs :-)

[http://www.ncbi.nlm.nih.gov/nuccore/NC_001422.1](http://www.ncbi.nlm.nih.gov/nuccore/NC_001422.1)

Enterobacteria phage phiX174 sensu lato, complete genome

5386 bp ss-DNA

~~~
jonmrodriguez
Hehe funny that you mention phiX174 in the context of programming, that virus
is amazing... Part of the reason phiX174 is so small is that it is
"compressed" by having overlapping genes; in one area, three genes overlap in
the same place! This is possible because there are 6 valid reading frames
(direction and start point) for reading DNA: {forward or backward} x {address
% 3 == 0, 1, or 2}.

In college I actually got to take part in refactoring that virus' genome into
a decompressed version with no gene overlaps. And it worked! The decompressed
version is still a functioning phage, and since there are no longer gene
overlaps, future genetic engineers will have a much easier time modifying the
phage as they see fit.

[http://www.sciencedirect.com/science/article/pii/S0042682212...](http://www.sciencedirect.com/science/article/pii/S0042682212004618)

~~~
GuiA
That's pretty amazing. I'm guessing DNA compactness is a survival advantage
for viruses, and that's how this emerged? Is gene overlap common in other
species?

~~~
wamatt
I would think the opposite may be true, given that compressed information
tends to be more sensitive to error, than uncompressed.

~~~
TazeTSchnitzel
Redundancy helps resistance to error, yeah. This thing could be quite easily
damaged in transmission.

------
TazeTSchnitzel
The Makefile is the most interesting part:
[http://www.ioccc.org/1994/Makefile](http://www.ioccc.org/1994/Makefile)

    
    
      smr: smr.c
      	@${RM} -rf smr
      	${CP} smr.c smr
      	${CHMOD} +x smr
    

Apparently, an empty file marked as executable will execute!

~~~
TillE
Because it's being interpreted as a shell script, I assume.

~~~
ChristianBundy
Without a hashbang it's actually interpreted as machine code, it just doesn't
have any machine instructions.

~~~
delroth
No, without a shebang it is interpreted as a shell script.

~~~
bodyfour
Correct. A file will only be considered a binary executable if it has a proper
header (ELF, Mach-O, etc) The default if no header and no shebang is to treat
it like a shell script.

In fact, an empty executable file has been used to implement /bin/true on some
old systems. Why take the added cost of a disk seek when just the information
in the inode will do?

~~~
TheSoftwareGuy
>In fact, an empty executable file has been used to implement /bin/true on
some old systems. Why take the added cost of a disk seek when just the
information in the inode will do?

why is this only on old systems? it seems very efficient.

~~~
rspeer
What's more efficient is that most shells don't bother running /bin/true at
all. "true" is just a shell builtin, so it doesn't need to spawn a process
just to get an obvious return value out of it.

------
Alupis
I'm not sure I understand how it's "self replicating"? An empty file, compiled
or not, won't replicate itself. The Makefile to compile the empty c file is
also rather large, but even it must be executed in a loop.

Can someone explain the basis of this contest and how this c file is "self-
replicating"?

~~~
michael_fine
I think what they were referring to was a quine

~~~
Alupis
yes, but is using an external program (make and cp) really count? I wouldn't
consider that really as "self-replicating".

~~~
fsniper
every self replicating entry in the competition is compiled with other
binaries.

~~~
maaku
And most of biology (including you).

------
avmich
There is PDP-11 command (one word, 16 bits) which makes a copy of itself into
a previous word (with address, in bytes, less by two) and passes the control
to the new copy. Octal 103737... or something like that.

Doesn't require make :) or cp and is pretty active - fills up all the memory
space below the starting point in no time.

------
51Cards
For those not understanding and wanting to see the "source" for this entry...
it was a Zero byte file.

~~~
TazeTSchnitzel
Download here:
[http://www.ioccc.org/1994/smr.c](http://www.ioccc.org/1994/smr.c)

~~~
JetSpiegel
Just post the source code here:

~~~
HaseebR7
Done.

------
silverfox17
I hang out on /r/dailyprogrammer sometimes - they had a challenge about these
types of programs the other day and called them "quines." Check through some
of these if you're interested, a few are 2 characters long (not sure how many
bytes that is):
[http://www.reddit.com/r/dailyprogrammer/comments/2n11w8/2014...](http://www.reddit.com/r/dailyprogrammer/comments/2n11w8/20141121_challenge_189_hard_write_a_quine/)

~~~
TheSoftwareGuy
2 characters is usually 2 bytes, unless they are using some weird unicode
format, in which case it shouldn't be longer than 8 i think.

------
sysk
Is the copyright notice supposed to apply to the empty program?

~~~
mojuba
Not sure about the copyright, but I wouldn't be surprised if someone patented
it in the US.

~~~
IsTom
Actually, there was a story about somebody selling 0-byte executable for DOS
allowing you to resume programs because of some peculiarity.

~~~
HCIdivision17
I'll be darned if I can find the URL to the story, but it is a brilliant
application of giving the customer what they wanted.

The short of it is that when you dropped back to the command line, early
versions of DOS didn't clear the memory. That meant that the program really
just went into stasis, but in practice it meant restarting; see, the program
ran off the floppy then, so to save or load to another disk was tricky.
Because memory would be executed from the same address, you could insert this
disk with an empty executable that would get DOS to send execution to that
address, which happens to be the program already in memory.

This had the huge boon of allowing you to drop to the command line, do
something, and the resume working! Apparently they sold the disks for like $5
(or pounds) each, and the customers were extremely pleased. And the programmer
was got a kick out of having rather impressive return per byte written :)

~~~
abecedarius
Here you go: [http://peetm.com/blog/?p=55](http://peetm.com/blog/?p=55)

~~~
HCIdivision17
I wish I could edit my comment - it wasn't even MS-DOS! But, yep, that is the
story. Hopefully I won't forget GO.COM in the future.

Thanks a mil for finding the link! I had a feeling I read the story from HN,
and so it was:

[https://news.ycombinator.com/item?id=5920732](https://news.ycombinator.com/item?id=5920732)

------
mct
I once wrote an implementation of the classic Redcode "Imp" program in x86
assembly. It does not satisfy the requirements of this contest, but it does
act as the Imp program, perpetually copying itself through RAM. :-)

I just uploaded it to [https://github.com/mct/assembly-
toys/tree/master/imp](https://github.com/mct/assembly-toys/tree/master/imp)

------
ismailmechbal
Related to this article is "Ken Thompson" reflections on Trusting Trust
[http://cm.bell-labs.com/who/ken/trust.html](http://cm.bell-
labs.com/who/ken/trust.html)

------
kremlin
lol not quite in the spirit of the challenge.

~~~
pdkl95
Forcing the creation of a new contest rule is a tradition in the IOCCC.

~~~
bluecalm
Meh. Empty program doesn't replicate itself. It's similar to recent rule-
nitpick discussion about selling for 0$. Selling for 0$ isn't selling and
nothing isn't replicating itself.

Definition of replicate is: to repeat or copy (something) exactly

Empty program doesn't copy or repeat anything. Entry rejected.

EDIT: It's not reddit, downvotes doesn't go here for disagreeing. The problem
is posed in natural language and it has its own rules. In natural language (at
least in English) doing nothing isn't copying or replicating. You may check
the dictionaries.

Next time someone will claim claim 1 million sales: million nothings for 0
dollars to nobodies.

EDIT (to other child)

Yes, empty set is subset of other sets but that's because the definition of
subset. Copy or replicate in natural language (in which the problem is posed)
mean something entirely different.

~~~
jamesrom
The empty set is a subset of the empty set.

~~~
eximius
Don't forget that the empty set is also the subset of the empty set, making
them equal. ;)

------
FireRabbit
In redcode

    
    
        mov 0,1
    

is the smallest self-replicating program

------
NaNaN
Really a good joke for “Every TEXT is a quine.”

------
Varcht
Thanks, I was pretty messed up just now after watching the movie Pi, now I'm
even worse....

~~~
mjcohen
In "Pi", the math is from the Dover book by Jahnke and Emde and the formula
for the ratio of the sides of the rectangle is wrong.

------
disputin
Isn't this a quine, rather than a self-replicating program? A quine produces
the source, and a self-replicating program should produce an executable - no?
This seems to be a fallacy of equivocation.

~~~
palunon
If you run it, it will replicate itself...

    
    
      $ ./smr >smr.out
      $ diff smr smr.out

------
chaosfox

      smr: smr.c
      	@${RM} -rf smr
      	${CP} smr.c smr
      	${CHMOD} +x smr

this is bullshit if you ask me..

~~~
simarpreet007
Agreed, WTF.

