14
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Related \$\endgroup\$ – Jo King Jul 5 '18 at 14:41
  • \$\begingroup\$ Also related (duplication instead of deletion) \$\endgroup\$ – JungHwan Min Jul 5 '18 at 14:42
  • 1
    \$\begingroup\$ Wasn'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. \$\endgroup\$ – Magic Octopus Urn Jul 5 '18 at 17:55
  • \$\begingroup\$ @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. \$\endgroup\$ – Sriotchilism O'Zaic Jul 5 '18 at 17:59
  • \$\begingroup\$ I can't find it either. I must be going slowly insane. \$\endgroup\$ – Magic Octopus Urn Jul 5 '18 at 18:01
7
\$\begingroup\$

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
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.