Radiation hardened Quine: Whatever doesn't kill you, simply makes you stronger
Welcome back to our series on Quines! We've delved deep into the world of self-replication, exploring everything from introns to multi-language shape-shifters. Now, let's push the limits of Quine resilience and talk about a fascinating concept: Radiation Hardened Quine.
As we've learned, a Quine is a harmonious blend of data and code. The data holds the program's source code, while the code itself knows how to interpret this data and reproduce both itself and the data. It's a beautiful dance of self-reference, where the data becomes the code, and the code brings the data to life.
Self healing
Now what if we are given only the data part of the Quine? Can we recover the code part and vice-versa? In the analogy of cellular biology we've been using, this is the equivalent of having the DNA given and wanting to reconstruct a cell.
Say, if I had given you only the data part of the original Quine we wrote, such as below:
Python:
data = "print('data =', repr(data)); print(data)"
You probably won't have much trouble recovering the original Quine, since the encoding used in data is so trivial. All you have to do is just copy-paste the value of the data
as code.
What if the data is encoded, say in ASCII, much like how DNA would be encoded in base pairs? Can you find out the code of the below data section and recover the original Python Quine I wrote?
Python:
data = [112, 114, 105, 110, 116, 40, 39, 100, 97, 116, 97, 32, 61, 32, 39, 44, 32, 100, 97, 116, 97, 41, 10, 112, 114, 105, 110, 116, 40, 98, 121, 116, 101, 115, 40, 100, 97, 116, 97, 41, 46, 100, 101, 99, 111, 100, 101, 40, 34, 97, 115, 99, 105, 105, 34, 41, 41] # ascii encoded
This process is called bootstrapping, and it is similar to the process of bootstrapping, say, a C compiler (you start with an initial C compiler, which may be much simpler, much less feature-full, or much less efficient, than the C compiler you want to build, and you run it on the sources of the desired C compiler, giving a first binary C compiler, which you use a second time to recompile its own sources).
In the book The C Programming Language, Dennis Ritchie, Brian Kernighan, states:
The operating system, the C compiler itself, and essentially all UNIX application programs are written in C.
The possibility of bootstrapping means that to some extent Quines are self-healing: if the code is damaged but still able to use the data to recover the original code, bootstrapping can be performed.
Essentially, a Radiation hardened Quine of order n is a program such that:
It works as a regular Quine, and replicates itself when run normally.
When run, after deleting at-most any n characters in the source, still produces the original Quine as is.
Note that bootstrapping won't be possible without the key, if say the data section used encryption instead of encoding.
1st-order RH Quine
A self-healing Quine in Ruby with an ASCII art depicting the "Radiation" symbol. Delete any one character in the source code, and check if it still prints the original when run.
Ruby: Try it online!
eval=eval=eval='eval$s=%q(eval(%w(puts((%q(eval=ev
al=eval=^Z^##^_/#{eval@eval@if@eval)+?@*10+%(.size
>#{(s=%(eval$s=%q(#$s)#)).size-1}}}#LMNOPQRS_##thx
.flagitious!## )+?@*12+%(TUVW XY/.i@rescue##
/_3141592653 589793+)+?@* 16+%(+271828
182845904; _987654321 0;;eval)+?
@*18+%("x =((#{s.s um}-eval.
_sum)%256 ).chr; ;eval)+?@
*12+%(.s can(//){ a=$`+x+$
^_a.unpa ck (^ H*^)[0].
hex%999989==#{s.unpac k("H*")[0].hex%999989
}&&eval(a)}#"##"_eval @eval####@(C)@Copyrig
ht@2014@Yusuke@Endoh@# ###)).tr("@_^",32.chr<
<10<<39).sub(?Z,s));e xit#AB CDEFGHIJK)*%()))#'##'
/#{eval eval if eval .size>692}}#LMNOPQRS
##thx.flagitious!## TUVWXY/.i rescue##/
3141592653589793+ +271828182845904;
9876543210;;eval "x=((42737-eval.
sum)%256).chr;;eval .scan(//){a=$`+x+$'
a.unpack('H*')[0].hex%999989==68042&&eval(a)}#"##"
eval eval#### (C) Copyright 2014 Yusuke Endoh ####
3rd-order RH Quine:
This is a Perl program, that is self healing upto loss of 3 characters.
Perl: (Due to issues in ASCII code copy pasting. Unable to Try Online)
eval+<eval+<eval+<eval+(q(FoPqOlengthFoBBPP181XXVVVVJJJKKKNdoWchopJFtPDevalMODx4KNFrPIPA-MN-TUV-ZPINFsPIFoPqOI.Fo.IQNevalFoINevalIFsPZyI.Fr.IT-UPINsayDFtJqJFsKPZyPT-UFWrYrKD.DEEEEQDx6NsayDNDforB1..4YforB1..4NexitQNevalFo)=~y=A-Z=-+;-AZz-~=r)####>####>####>####>####>####>
;
;
;
;
eval+<eval+<eval+<eval+(q(FoPqOlengthFoBBPP181XXVVVVJJJKKKNdoWchopJFtPDevalMODx4KNFrPIPA-MN-TUV-ZPINFsPIFoPqOI.Fo.IQNevalFoINevalIFsPZyI.Fr.IT-UPINsayDFtJqJFsKPZyPT-UFWrYrKD.DEEEEQDx6NsayDNDforB1..4YforB1..4NexitQNevalFo)=~y=A-Z=-+;-AZz-~=r)####>####>####>####>####>####>
;
;
;
;
eval+<eval+<eval+<eval+(q(FoPqOlengthFoBBPP181XXVVVVJJJKKKNdoWchopJFtPDevalMODx4KNFrPIPA-MN-TUV-ZPINFsPIFoPqOI.Fo.IQNevalFoINevalIFsPZyI.Fr.IT-UPINsayDFtJqJFsKPZyPT-UFWrYrKD.DEEEEQDx6NsayDNDforB1..4YforB1..4NexitQNevalFo)=~y=A-Z=-+;-AZz-~=r)####>####>####>####>####>####>
;
;
;
;
eval+<eval+<eval+<eval+(q(FoPqOlengthFoBBPP181XXVVVVJJJKKKNdoWchopJFtPDevalMODx4KNFrPIPA-MN-TUV-ZPINFsPIFoPqOI.Fo.IQNevalFoINevalIFsPZyI.Fr.IT-UPINsayDFtJqJFsKPZyPT-UFWrYrKD.DEEEEQDx6NsayDNDforB1..4YforB1..4NexitQNevalFo)=~y=A-Z=-+;-AZz-~=r)####>####>####>####>####>####>
;
;
;
;
14th-order RH Quine
A Befunge program which is so resilient, that can handle deletions upto 14 characters!
Befunge: Try it online!
f00f00f00f00f00f00f00f00f00f00f00f00f00f00f0xxxxxxxxxxxxxxx"""""""""""""""fffffffffffffff'''''''''''''''000000000000000\\\\\\\\\\\\\\\'''''''''''''''000000000000000\\\\\\\\\\\\\\\'''''''''''''''fffffffffffffff\\\\\\\\\\\\\\\111111111111111---------------:::::::::::::::!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!000000000000000aaaaaaaaaaaaaaa---------------bbbbbbbbbbbbbbb---------------***************jjjjjjjjjjjjjjj$$$$$$$$$$$$$$$'''''''''''''''+++++++++++++++kkkkkkkkkkkkkkk,,,,,,,,,,,,,,,333333333333333kkkkkkkkkkkkkkk$$$$$$$$$$$$$$$000000000000000{{{{{{{{{{{{{{{'''''''''''''''888888888888888uuuuuuuuuuuuuuu'''''''''''''''!!!!!!!!!!!!!!!111111111111111+++++++++++++++'''''''''''''''xxxxxxxxxxxxxxx###############;;;;;;;;;;;;;;;:::::::::::::::!!!!!!!!!!!!!!!kkkkkkkkkkkkkkk@@@@@@@@@@@@@@@dddddddddddddddkkkkkkkkkkkkkkk:::::::::::::::eeeeeeeeeeeeeeekkkkkkkkkkkkkkk,,,,,,,,,,,,,,,;;;;;;;;;;;;;;;
In the iconic film Jurassic Park, chaos theorist Dr. Ian Malcolm utters the now-famous line, Life finds a way, as a response to the park's founder, John Hammond, who naively believes he can control the genetically engineered dinosaurs.
Dr. Ian Malcolm: John, the kind of control you're attempting simply is… it's not possible. If there is one thing the history of evolution has taught us it's that life will not be contained. Life breaks free, it expands to new territories and crashes through barriers, painfully, maybe even dangerously, but, uh… well, there it is.
Henry Wu: You're implying that a group composed entirely of female animals will… breed?
Dr. Ian Malcolm: No, I'm, I'm simply saying that life, uh… finds a way.
In case, you've been living under a rock and haven't yet watched the movie; Despite the park's sophisticated security measures, the dinosaurs escape, proving Malcolm's point that life is inherently unpredictable and extremely resilient.
So, next time you encounter a Quine, take a moment to appreciate its resilience and the potential for self-repair that lies within its code. It's a testament to the power of self-reference and the enduring spirit of digital life.
Sources and references:
Code Golf Radiation Hardened Quine, Code Golf post to write the highest nth-order RH Quine.
Quines (self-replicating programs), blog by David Madore.
Radiation-hardened Quine, GitHub by Yusuke Endoh.
Bootstrapping (compilers), wiki page.
The Development of the C Language, paper by Dennis M. Ritchie.
Life finds a way - Dialogue, Youtube video clip from the movie Jurrassic Park.
Radiation Hardened Quine, self-referencing blog that has a 1st order radiation hardened slug in the url (../rhquine).
Subscribe to my newsletter
Read articles from Darshan A S directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Darshan A S
Darshan A S
Tricking rocks into thinking, at Google.