Make a Radiation Hardened Quine

15

2

Last night I was looking for the Radiation Hardened Quine challenge, but I couldn't find it. Turns out no one has asked it yet! So here it is:

Your task is to make a quine, that is a non-empty computer program that prints it's own source without reading it. In addition if you remove any one byte from your original program the new program should print the source of your original program.

This is so answers are scored in bytes with fewer bytes being better.

Post Rock Garf Hunter

Posted 2018-07-05T14:33:05.743

Reputation: 55 382

Related – Jo King – 2018-07-05T14:41:12.133

Also related (duplication instead of deletion) – JungHwan Min – 2018-07-05T14:42:16.093

1Wasn't this asked, unanswered for 1.5 years and then deleted b/c the user account was deleted or something? Not saying I don't want one though +1. Just swear I've seen it. – Magic Octopus Urn – 2018-07-05T17:55:14.803

@MagicOctopusUrn I thought it existed. I wanted to answer it but couldn't find it. If someone finds the old one I'd be happy to dupe hammer this myself. – Post Rock Garf Hunter – 2018-07-05T17:59:56.957

I can't find it either. I must be going slowly insane. – Magic Octopus Urn – 2018-07-05T18:01:18.787

Was it not just sitting in the Sandbox for an eternity? (Although, I could've sworn I saw it on Main, as well) – Shaggy – 2018-07-05T18:07:07.043

Surely this is just an n=1 subset/version of https://codegolf.stackexchange.com/q/57257/42963 ?

– AdmBorkBork – 2018-07-05T18:25:41.480

@AdmBorkBork Any answer there is valid here and vice versa however the scoring is drastically different. This question is straight code-golf and that is a code-challenge. – Post Rock Garf Hunter – 2018-07-05T18:34:35.497

@AdmBorkBork, that's the one I was thinking of and assumed was the one Cat was referring to. – Shaggy – 2018-07-05T19:14:37.660

@MagicOctopusUrn Can't find any.

– user202729 – 2018-07-06T02:10:49.417

No Compile Error allowed if one char removed? – l4m2 – 2018-07-06T12:43:22.993

@l4m2 As long as the compiled program works as intended, compiler errors are fine. – Post Rock Garf Hunter – 2018-07-06T15:09:51.783

@CatWizard Are you sure this question has an answer – Agile_Eagle – 2018-07-10T17:24:58.637

@Agile_Eagle Yes here is one..

– Post Rock Garf Hunter – 2018-07-10T17:26:25.103

I think the radiation hardened quine question used to have an answer in A Pear Tree with the question being a code challenge based on how many bytes could be changed with the program still working. – fəˈnɛtɪk – 2018-07-10T20:53:57.990

Answers

7

Gol><>, 49 45 bytes

<<H~Kla}\`q%2l}}ss2"<\
<<H~Kla}\`q%2l}}ss2"<\

Try it online!

Verification!

I did this in Gol><> rather than ><> because the former has the handy K operator that copies the top n items on the stack, which makes duplicating the clean copy of the source code easier.

Explanation:

This works by having two copies of the executing code, and redirecting to the second one if the first is damaged. This fails when the last \ or the middle newline is removed, both of which are compensated for later.

<<                       Redirect left 
                    <\  Switch to other source code if this line is irradiated
                   "     Push source with wrapping string literal
                ss2      Push quote
              }}         Move "< to end
          q%2l           If the length of the stack is not right
        \`               Push an extra \
       }                 Move the \ to the end
      a                  Newline
    Kl                   Duplicate the stack
   ~                     Pop the extra newline
  H                      Halt and print stack

Jo King

Posted 2018-07-05T14:33:05.743

Reputation: 38 234

I golfed off 2 bytes!!! – KrystosTheOverlord – 2019-02-08T13:58:15.573

https://tio.run/##S8/PScsszvj/38bGo67aO6c20V41Oae2tqi42KhIySaGC4f4//8A Here is a link! – KrystosTheOverlord – 2019-02-08T13:58:19.620

I just realized I did it completely wrong, sorry, there is one set of characters that if they are missing, the program just doesn't work... – KrystosTheOverlord – 2019-02-08T14:04:06.040

@KrystosTheOverlord You can use the verification program to test your programs – Jo King – 2019-02-09T00:05:35.863