News for hackers. Stuff that matters.
Re:Radiation-hardened quine by danslimmon on Friday February 21, 2014 @02:51PM (#7279014)
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

Re:Radiation-hardened quine by mdisraeli on Friday February 21, 2014 @07:49PM (#7280470)
Nice, Love it when people actually perform experiments! :D In how many cases was the wrong output still functional?
Re:Radiation-hardened quine by gojomo on Saturday February 22, 2014 @04:40AM (#7281567)
Neat! Was each test of n random 1-character removals, or 1 removal of an n-character run?
Re:Radiation-hardened quine by danslimmon on Saturday February 22, 2014 @09:59AM (#7282203)
The first one.
Re:Radiation-hardened quine by p4bl0 on Friday February 21, 2014 @04:25PM (#7279540)
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.

Re:Radiation-hardened quine by Cthulhu_ on Friday February 21, 2014 @10:31AM (#7277377)
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?
Re:Radiation-hardened quine by hrjet on Friday February 21, 2014 @10:36AM (#7277401)
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.

Re:Radiation-hardened quine by jonmrodriguez on Friday February 21, 2014 @07:47PM (#7280459)
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
Re:Radiation-hardened quine by Schwolop on Monday February 24, 2014 @09:27PM (#7294902)
Yes, and I was thoroughly disappointed by this result. So - new challenge: a radiation hardened quine in less than two times the characters of the equivalent non-radiation hardened version.
Re:Radiation-hardened quine by joi_degn on Friday February 21, 2014 @10:36AM (#7277398)
I didnt look at the code and am not knowledgeable in this kind of coding but unless I am wrong, if the program simply would contain the same code twice each of these 2 codes would have to contain the same code twice ad infinitum.
Re:Radiation-hardened quine by notimetorelax on Saturday February 22, 2014 @07:12AM (#7281838)
If we follow your reasoning than quine itself is not possible.
Re:Radiation-hardened quine by dllthomas on Friday February 21, 2014 @10:19AM (#7277310)
Fascinating exercise. "Deleting one character" seems a phenomenally unlikely outcome of radiation, though.
Re:Radiation-hardened quine by fnordfnordfnord on Friday February 21, 2014 @11:31AM (#7277697)
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_...
Re:Radiation-hardened quine by dllthomas on Friday February 21, 2014 @11:44AM (#7277776)
That seems to be a flipped bit, by far the most likely kind of problem due to radiation.
Re:Radiation-hardened quine by ygra on Friday February 21, 2014 @10:52AM (#7277492)
A harder task might be "Randomly delete, add or mutate a single character".

We had a few similar tasks on CGSE, e.g.

• http://codegolf.stackexchange.com/q/4486/15

• http://codegolf.stackexchange.com/q/18087/15

Re:Radiation-hardened quine by dllthomas on Friday February 21, 2014 @11:24AM (#7277668)
Addition and deletion anywhere but the end seems overwhelmingly unlikely.
Re:Radiation-hardened quine by ygra on Friday February 21, 2014 @11:48AM (#7277809)
Depends on how the code is stored in memory ... with ropes addition or deletion anywhere could happen.
Re:Radiation-hardened quine by dllthomas on Friday February 21, 2014 @11:55AM (#7277856)
True! But:

1) it's still less likely - most of the data is almost certainly characters of content, not sizes;

2) it's unlikely to be robust against flipped bits in pointers in the rope structures (even if implemented as indexes);

and 3) there is no reason to expect it to be limited to one byte (if an addition or deletion happens, "more than one byte" is far more likely than "one byte").

Re:Radiation-hardened quine by TrainedMonkey on Friday February 21, 2014 @01:49PM (#7278602)
I agree, flipping random bit is more likely. I.E. mutating random character into some other random character (does not have to be printable one). This also has a pretty strong assumption that Ruby itself is not corrupted.
Re:Radiation-hardened quine by foobarqux on Friday February 21, 2014 @11:48AM (#7277808)
Corrupting one bit is likely but if the rest of your system is not radiation hardened it isn't very helpful.
Re:Radiation-hardened quine by dllthomas on Friday February 21, 2014 @11:57AM (#7277872)
Yes, my objection wasn't that this failed to be a practical complete solution to radiation, but that there wasn't really a tie to radiation at all.
Re:Radiation-hardened quine by mey on Friday February 21, 2014 @07:57PM (#7280495)
Wouldn't radiation flip a bit, rather than remove a character?
Re:Radiation-hardened quine by zefhous on Friday February 21, 2014 @10:56AM (#7277515)
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...

Re:Radiation-hardened quine by scriby on Friday February 21, 2014 @06:14PM (#7280097)
The whole paragraph can be translated like this:

"I didn't really think I'd be able to write this [program], but somehow I was able too. Ruby is scary, isn't it? I wonder if you could write this in another language?"

Re:Radiation-hardened quine by audunw on Friday February 21, 2014 @11:15AM (#7277605)
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.

Re:Radiation-hardened quine by ojii on Friday February 21, 2014 @11:20AM (#7277632)
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?"
Re:Radiation-hardened quine by iterion1 on Friday February 21, 2014 @11:54AM (#7277850)
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...

Re:Radiation-hardened quine by ojii on Friday February 21, 2014 @12:28PM (#7278069)
Yes it's one of those "funny" words in Japanese that is highly context sensitive, so you're probably right.
Re:Radiation-hardened quine by minikomi on Friday February 21, 2014 @09:12PM (#7280694)
Yeah.. 恐ろしい is kind of a "Wondrous and terrifying" blend
Re:Radiation-hardened quine by trapezoid on Friday February 21, 2014 @11:39AM (#7277748)
Chinese and Japanese grammar have very little relation to each other - about as much as Chinese and English. (The alphabets are, of course, very similar, as the Japanese adopted Chinese characters.)
Re:Radiation-hardened quine by stcredzero on Friday February 21, 2014 @11:56AM (#7277868)
The Japanese use Chinese characters. The Japanese also have alphabets. (At least two.) But Chinese characters aren't exactly an alphabet and the Japanese don't use Chinese characters directly as an alphabet, though many characters are based on Chinese ones.
Re:Radiation-hardened quine by pjlegato on Friday February 21, 2014 @12:22PM (#7278023)
Since we're being technical, Japanese does not have any alphabet as such; an alphabet has, by definition, a 1 to 1 correspondence between a single character and a sound. Japanese uses syllabaries ('kana' in Japanese), where almost all characters represent more than 1 sound. Hiragana is typically used to write Japanese words and grammatical particles, while katakana is typically used to write foreign words and for special emphasis, roughly analogous to how boldface type is used in English. Both of these kana are derived from Chinese characters, greatly simplified, though the relationship is somewhat distant.

Japanese also uses a third writing system called kanji, also not an alphabet, whose name literally means "Han [Chinese] characters" in Japanese. Kanji are logographs, where one character represents one entire word or concept rather than sounds.

Most kanji are identical or very similar to modern Chinese characters and are readily intelligible to a Chinese reader, at least in a general sense, though some have diverged a bit.

Grammar is another matter entirely. Japanese is a language isolate, a language that is not related to any other known language. (Someone will reply that it's distantly related to Korean, but this is a fringe theory in linguistics that is not widely accepted.) Chinese and Japanese are not grammatically related at all, and any similarity between their syntaxes is coincidental.

Re:Radiation-hardened quine by aninhumer on Friday February 21, 2014 @04:51PM (#7279671)
>a 1 to 1 correspondence between a single character and a sound.

While you're correct that the Japanese writing system is not an alphabet, I feel like your definition here is so vague it almost contradicts your point. After all, each kana character has a much closer correspondence with a particular "sound" than many actual alphabets.

So to clarify, the characters of an alphabet (notionally) correspond to particular phonemes.

Re:Radiation-hardened quine by DougBTX on Friday February 21, 2014 @12:47PM (#7278203)
> an alphabet has, by definition, a 1 to 1 correspondence between a single character and a sound.

Do any languages have an alphabet according to this definition?

Re:Radiation-hardened quine by Sharlin on Friday February 21, 2014 @08:03PM (#7280512)
Finnish almost does. There are minor exceptions, though.
Re:Radiation-hardened quine by anon4 on Friday February 21, 2014 @05:19PM (#7279841)
Cyrillic-using languages generally do.
Re:Radiation-hardened quine by gurkendoktor on Saturday February 22, 2014 @05:05AM (#7281634)
The 'o' in Russian is pronounced 'a' half of the time (non-scientific estimate). :(
Re:Radiation-hardened quine by stcredzero on Friday February 21, 2014 @01:30PM (#7278492)
Korean?
Re:Radiation-hardened quine by snogglethorpe on Friday February 21, 2014 @05:43PM (#7279957)
At the least, Korean has voiced-versus-non-voiced-depending-on-word-position changes, and IIRC there are other similar rules (about changing pronunciation in certain contexts) as well.
Re:Radiation-hardened quine by alxndr on Friday February 21, 2014 @05:15PM (#7279821)
IIRC Hangul has some weird pronunciation quirks depending on where some letters are in a syllable.
Re:Radiation-hardened quine by snogglethorpe on Friday February 21, 2014 @06:07PM (#7280060)
> Japanese is a language isolate, a language that is not related to any other known language. Someone will reply that it's distantly related to Korean, but this is a fringe theory in linguistics that is not widely accepted

When using some strict definition of "related" (e.g. "neither language is a strict descendent of the other"), that may be true, but anybody that's studied both languages has probably noticed that there's an eery similarity between the two, even if it's merely the result of many centuries of cross-pollenization....

My own experience is not so great, I've only studied Korean a bit, but I did study it in Japanese (which I know fairly well), and the similarity made it a lot easier, because so many things corresponded 1-to-1... However Korean friends that are fluent in Japanese constantly rave about how easy it was for them to learn, not just because of the huge amount of shared Chinese-derivative vocabulary (many words are completely identical, with formulaic changes in pronunciation), but because the whole structure of grammar, sentence/conversation-planning, idioms, etc, is so similar that a huge proportion of their Korean instincts pretty much just work as-is in Japanese.

Re:Radiation-hardened quine by meric on Sunday February 23, 2014 @08:37AM (#7285850)
Continuing on,

Spoken Japanese and Chinese have little to no relation, except for Chinese words imported into Japanese.

Hiragana, however, is derived from Chinese characters thousands of years ago. The Chinese characters were used in Japanese writing to write words phonetically.

See http://en.wikipedia.org/wiki/File:Hiragana_origin.svg

Re:Radiation-hardened quine by hyborg787 on Friday February 21, 2014 @10:33AM (#7277385)
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.
Re:Radiation-hardened quine by jxf on Friday February 21, 2014 @10:41AM (#7277428)
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. :)
Re:Radiation-hardened quine by ojii on Friday February 21, 2014 @11:22AM (#7277653)
couldn't one make 3 copies and take the two that are equal as non-modified?
Re:Radiation-hardened quine by eklavya on Friday February 21, 2014 @11:39AM (#7277746)
So like above said, error correction for at most one error.
Re:Radiation-hardened quine by Guillaume86 on Saturday February 22, 2014 @10:41AM (#7282362)
2 copy + one hash could do the same job?
Re:Radiation-hardened quine by throwaway_yy2Di on Friday February 21, 2014 @10:20AM (#7277316)
Hard mode: flip bits in the interpreter's process memory as it's running.
Re:Radiation-hardened quine by spoiler on Friday February 21, 2014 @10:39AM (#7277414)
Extreme mode: Run this code on an abacus.
Re:Radiation-hardened quine by pavel_lishin on Friday February 21, 2014 @12:47PM (#7278205)
Olympic mode: while drunk.
Re:Radiation-hardened quine by foobarqux on Friday February 21, 2014 @11:49AM (#7277814)
Or in the program counter or ALU, etc.
Re:Radiation-hardened quine by michaelmior on Friday February 21, 2014 @11:19AM (#7277626)
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 :)
Re:Radiation-hardened quine by lmkg on Friday February 21, 2014 @01:12PM (#7278371)
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.
Re:Radiation-hardened quine by michaelmior on Friday February 21, 2014 @01:30PM (#7278494)
Good point :)
Re:Radiation-hardened quine by zackmorris on Friday February 21, 2014 @12:45PM (#7278189)
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

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

Re:Radiation-hardened quine by usefulcat on Friday February 21, 2014 @02:01PM (#7278691)
> Does anyone know of a language or operating system that uses Reed–Solomon error correction on every file?

A while back, after losing some personal photographs to bit rot, I became curious about this and did some experimentation with RS. The biggest drawback I found was that even with a relatively fast processor it is slow compared to typical disk read/write speeds. I concluded that the ZFS approach of RAID + checksums would be preferable.

Re:Radiation-hardened quine by CraigJPerry on Friday February 21, 2014 @01:03PM (#7278308)
ZFS (the file system) goes to some fairly extreme lengths to validate data. It effectively doesn't trust anything past the south bridge.
Re:Radiation-hardened quine by MaysonL on Friday February 21, 2014 @06:27PM (#7280150)
In the early 1970's I implemented the driver for, and programs using, a digital videotape drive (IIRC, it incorporated an Ampex 2 inch reel-to-reel recorder, and used the sound track for positioning information). It used hardware Reed-Solomon error correction (IIRC, it was capable of correcting up to 11-bit errors). It stored a massive (for the time) database of scanned drawings for a number of aircraft maintenance manuals.
Re:Radiation-hardened quine by Tomte on Saturday February 22, 2014 @06:20AM (#7281756)
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.

Re:Radiation-hardened quine by jmpe on Saturday February 22, 2014 @04:33PM (#7283715)
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.

Re:Radiation-hardened quine by NAFV_P on Friday February 21, 2014 @01:21PM (#7278433)

  $ 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
Re:Radiation-hardened quine by tomp on Friday February 21, 2014 @11:10AM (#7277577)
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

Re:Radiation-hardened quine by samatman on Friday February 21, 2014 @12:26PM (#7278055)
Ironically, Linguist+Pygments, the detection and highlighting engine, is a Ruby tool.
Re:Radiation-hardened quine by halostatue on Friday February 21, 2014 @10:26PM (#7280875)
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

Re:Radiation-hardened quine by yincrash on Saturday February 22, 2014 @10:42AM (#7282367)
same author wrote a 50 language quine: https://github.com/mame/quine-relay
Re:Radiation-hardened quine by th0ma5 on Friday February 21, 2014 @10:34AM (#7277392)
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.
Re:Radiation-hardened quine by NAFV_P on Saturday February 22, 2014 @05:30PM (#7283914)
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

Re:Radiation-hardened quine by jheriko on Friday February 21, 2014 @10:42AM (#7277432)
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?

Re:Radiation-hardened quine by iliis on Friday February 21, 2014 @10:53AM (#7277502)
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.

Re:Radiation-hardened quine by jheriko on Tuesday March 04, 2014 @06:52PM (#7344150)
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...

Re:Radiation-hardened quine by heydenberk on Friday February 21, 2014 @04:31PM (#7279570)
If you had asked me I might've said this was impossible.