
Radiation-hardened quine - epsylon
https://github.com/mame/radiation-hardened-quine
======
danslimmon
I was curious how well this quine would withstand having more than one
character removed, so I performed a test. I did 1000 iterations removing 2
characters each time, then 1000 more removing 3 characters each time, and so
on.

Here are the results up to 23 removals:
[http://i.imgur.com/PwWN7Z7.png](http://i.imgur.com/PwWN7Z7.png)

~~~
gojomo
Neat! Was each test of n random 1-character removals, or 1 removal of an
n-character run?

~~~
danslimmon
The first one.

------
p4bl0
Nice!

This reminds me of a work I did as an undergrad which landed in a paper called
"Can a Program Reverse-Engineer Itself?". The idea is to take any
program/function and make it a quine so you can retrieve its original code
even if it has been obfuscated. You can find the paper here:
[http://pablo.rauzy.name/research.html#imacc11](http://pablo.rauzy.name/research.html#imacc11).

------
Cthulhu_
I can't read this code at all, but, does this code basically contain the same
code twice, so if something from the first half is removed the second half
saves it?

~~~
hrjet
Yes, Line 15: /#{eval eval if eval==instance_eval}}/.i rescue##/

They are checking the two instances and rescuing the corrupted one. But how
exactly it works is beyond me.

~~~
jonmrodriguez
Also, in line 17, I think it's running whichever of the two codes is longer
(since the longer one is the one that didn't have a byte deleted)

    
    
        eval eval"[eval||=9,instance_eval||=9].max_by{|s|s.size}#"##"
    

See the max_by ... size part

------
dllthomas
Fascinating exercise. "Deleting one character" seems a phenomenally unlikely
outcome of radiation, though.

~~~
fnordfnordfnord
Granted it's not "deleting" a character but here, if you haven't seen it:
[https://blogs.oracle.com/ksplice/entry/attack_of_the_cosmic_...](https://blogs.oracle.com/ksplice/entry/attack_of_the_cosmic_rays1)

~~~
dllthomas
That seems to be a flipped bit, by far the most likely kind of problem due to
radiation.

------
mey
Wouldn't radiation flip a bit, rather than remove a character?

------
zefhous
Here's the google translate link to his blog post about it.

My favorite part: "Ruby I terrible."

[http://translate.google.com/translate?sl=auto&tl=en&js=n&pre...](http://translate.google.com/translate?sl=auto&tl=en&js=n&prev=_t&hl=en&ie=UTF-8&u=http%3A%2F%2Fd.hatena.ne.jp%2Fku-
ma-me%2F20140219)

~~~
audunw
Japanese is Subject-Object-Verb order, so it was probably "My Ruby (is)
terrible". But I don't know Japanese so I can't tell you for sure.

Chinese would also drop the verb in this case, so I'm assuming they might do
that in Japanese as well.

~~~
ojii
Ruby is the subject in that sentence, not sure why gtranslate injects an "I".
I'd translate it as "Ruby is scary, isn't it?"

~~~
iterion1
Could also be 'surprising'. With the context of the sentence before it is
basically, "I thought this would be hard to write. Ruby is surprising."

Also, the author is a contributor to ruby on github, so I doubt he is negative
towards the language.

[http://jisho.org/words?jap=%E6%81%90%E3%82%8D%E3%81%97%E3%81...](http://jisho.org/words?jap=%E6%81%90%E3%82%8D%E3%81%97%E3%81%84&eng=&dict=edict)

~~~
ojii
Yes it's one of those "funny" words in Japanese that is highly context
sensitive, so you're probably right.

------
hyborg787
Exercise for the reader, make a quine that still works even if any one
character is mutated (by 1 bit or 8?), rather than deleted.

~~~
jxf
That definitely wouldn't work with this strategy (two copies), because you
wouldn't be able to tell which copy was the mutated one. Error-correcting
codes to the rescue. :)

~~~
ojii
couldn't one make 3 copies and take the two that are equal as non-modified?

~~~
eklavya
So like above said, error correction for at most one error.

------
throwaway_yy2Di
Hard mode: flip bits in the interpreter's process memory as it's running.

~~~
spoiler
Extreme mode: Run this code on an abacus.

~~~
pavel_lishin
Olympic mode: while drunk.

------
michaelmior
Depends on how you define "works." The program continues to output the
original source code after the deletion, and ceases to be a quine. Still a
very cool trick though :)

~~~
lmkg
But reverting to the original source gives the program a stability property
that will maintain functionality through multiple generations. Outputting the
modified source would cause the program to accrue errors over time, meaning
eventually entropy would win.

~~~
michaelmior
Good point :)

------
zackmorris
Interesting! Does anyone know of a language or operating system that uses
Reed–Solomon error correction on every file?

[https://en.wikipedia.org/wiki/Reed–Solomon_error_correction](https://en.wikipedia.org/wiki/Reed–Solomon_error_correction)

Or to top that, imagine a computer where the entire memory space, perhaps
shared with persistent flash memory, was encoded in this manner, so that even
the filesystem was protected against bit flips.

When I was doing Mac repair a few years back, the majority of the PowerMac G5s
that came through the doors died premature deaths for two reasons: the ram was
in a bad spot which caused the board to bend and crack on insertion, and the
ram was non-ECC so it was notoriously difficult to isolate a bad ram chip. It
was the most unreliable Mac I ever diagnosed, by perhaps an order of
magnitude.

Contrast that with the Mac Pro, which used ECC and was so much more reliable
that I don't remember seeing a single Mac Pro fail in the 3 years I was there.

Imagine how stable a Reed–Solomon computer would be..

~~~
Tomte
In safety-related system you usually don't try to correct bit flips (at least
in my niche), but you've got lots and lots of mechanisms ensuring that bit
flips are discovered. Even more, hardware faults like stuck-at bits and so on
need to be discovered, as well.

The downside is that all those checks are _slow_.

~~~
jmpe
For more info on this search for "defensive programming", "Immunity-aware
programming" and "preventitive programming". Several hardware companies have
manuals/rules for programming in harsh environments.

Even if you're not into hardware it's worth a look, lots of cool tips.

------
NAFV_P

      $ git clone the_quine
      $ cd the_quine
      $ ruby the_quine
      The program 'ruby' can be found in the following packages:
       * ruby1.8
       * ruby1.9.1
      # shit I don't have ruby
      $ sudo apt-get install ruby1.9.1
      # 200 bytes/s, terrible
      # ... what's going on? Ah finally.
      $ touch output
      $ ruby rbquine.rb > output
      $ diff rbquine.rb output
      # nowt

------
tomp
This would be much easier to understand if GitHub had proper ruby syntax
highlighting. Just yesterday I was testing this, it appears they use very
simplistic algorithm for parsing Ruby string interpolation - probably just
regexes, which cannot handle nesting.

[https://gist.github.com/tomprimozic/9113077](https://gist.github.com/tomprimozic/9113077)

~~~
samatman
Ironically, Linguist+Pygments, the detection and highlighting engine, is a
Ruby tool.

~~~
halostatue
Pygments is a Python tool, accessed through RubyPython* (for which I should
really make sure it still works with Ruby 2.1 and maybe start trying to figure
out how to make it work with Py3.)

We have a few crashes that I can't figure out (but am putting in the test
suite).

* [https://bitbucket.org/raineszm/rubypython/src](https://bitbucket.org/raineszm/rubypython/src)

------
yincrash
same author wrote a 50 language quine: [https://github.com/mame/quine-
relay](https://github.com/mame/quine-relay)

------
th0ma5
I recommend reading specs for low power digital radio protocols like WSPR for
ideas around basic error correction. Just something I did recently and was
fun.

------
NAFV_P
I looked at his git profile, I recognised the name: Yusuke Endoh - multiple
IOCCC winner. Here is one of my favourites:

[http://www.ioccc.org/2012/endoh1/hint.html](http://www.ioccc.org/2012/endoh1/hint.html)

------
jheriko
i wonder how far this can be taken... e.g. flipping or setting a random string
of bits that would be physically contiguous in hardware as if a real neutron
came smashing into the memory... if doing it during run can be achieved etc.

how about a real native app with instructions? i'd never expect something as
high level and wooly as ruby in systems that will be exposed to radiation.
that's just asking for failure imo... how robust is the interpreter for
instance?

~~~
iliis
A friend of mine writes firmware for embedded devices like automatic door
controls. Besides having very well designed and redundant hardware (multiple
PSUs etc.) the software does a lot of things to keep itself running robustly.
For example, the microcontroller regularly tests its own memory for bad blocks
and compensates accordingly - similiar to what flash memory controllers do.

So yeah, even if you don't go into space or inside a nuclear reactor software
can be written to tolerate a lot of harware failures.

~~~
jheriko
thats interesting to know... i think you misunderstand me though. neutrons
rain down on your hardware right now from deep space with significant
energies... nuclear reactors aside.

this is the primary reason afaik for things like ecc and encasing your
hardware in boro-silicate glass...

------
heydenberk
If you had asked me I might've said this was impossible.

