11
\$\begingroup\$

A radiation-hardened quine can take a hit and stay standing, but nobody ever said that the quine can't be a wuss about it.

For this challenge, you should write a quine that:

  • If no characters are removed, prints its source code normally.
  • Iff any one character is removed, prints the original program's source code, followed by a new line and then this text:

    Owie! That hurt!
    

    You should only print the original plus that.

Standard quine rules apply for this challenge, and the shortest valid code in bytes wins. See also Radiation Detector!

\$\endgroup\$
4
  • 6
    \$\begingroup\$ I'm not sure what this adds to the site beyond the quine and radiation hardened quine challenges. \$\endgroup\$
    – GMills
    Commented Feb 8, 2019 at 2:29
  • 7
    \$\begingroup\$ There's a little bit of new complexity in both retaining the same behaviour while irradiated, while also being able to tell that it has been irradiated. \$\endgroup\$
    – Jo King
    Commented Feb 8, 2019 at 12:34
  • \$\begingroup\$ Can I choose which character is deleted? \$\endgroup\$
    – seshoumara
    Commented Dec 12, 2022 at 16:06
  • \$\begingroup\$ @seshoumara no, you can't. That'd sorta defeat the point of radiation-hardening. \$\endgroup\$
    – Nissa
    Commented Dec 15, 2022 at 2:30

1 Answer 1

5
\$\begingroup\$

Backhand, 203 bytes

""###:::[[[:::::::::)))))))))888999***EEE666***333+++ssscccjjjlll222%%%'''ccc***333+++xxx(((sssaaa'''OOO'''www'''iii'''eee'''!!!'''   '''TTT'''hhh'''aaa'''ttt'''   '''hhh'''uuu'''rrr'''ttt'''!!!rrr~~~HHH

Attempt This Online! or with a char removed.

Note: This is based on Jo King's answer to a similar question.

Every character here is repeated three times as a form of radiation hardening (aside from the leading "), since Backhand by default executes every third instruction. I'll explain the deduplicated code:

"#:[:::)))89*E6*3+scjl2%'c*3+x(sa'O'w'i'e'!' 'T'h'a't' 'h'u'r't'!r~H # Wrap around, pushing every third character of the code aside from `"`, forwards then backwards
 #                                                                   # NOP      
  :[                                                                 # Duplicate and increment the # into a "
    :::)))                                                           # Push three copies of the char to the other stack
          89*E                                                       # If it's not equal to 72 ("H")
              6*3+scj                                                # Jump back to the start of the loop
                     l2%'c*3+                                        # Is the length of the pushed code odd (char missing)?
                             x(s                                     # Switch to the other stack
                                a'O'w'i'e'!' 'T'h'a't' 'h'u'r't'!    # If so, push "\nOwie! That hurt!"
                                                                 r~  # Remove a redundant `"`
                                                                   H # Terminate and print the contents of the stack as a string
\$\endgroup\$
2
  • \$\begingroup\$ finally an answer to this challenge! \$\endgroup\$ Commented May 28 at 10:48
  • \$\begingroup\$ Never heard of a radiation-hardened quine before. This is one of the coolest things I've ever seen. \$\endgroup\$
    – SanguineL
    Commented May 28 at 15:32

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