1
\$\begingroup\$

Simple task, write a program/function that returns error if and only if presented with itself.

The program must give a valid output for any input other than itself.

For the error part, you can only use errors already built in errors that comes with your language of choice. New/ self-defined error messages are not allowed.

The output should be of the same type as the input. (int, float, string, array, boolean, etc.) Except in the case if presented with itself of course.

Standard loopholes forbidden, lowest byte wins.

\$\endgroup\$
1
\$\begingroup\$

05AB1E, 20 bytes

"34çìD«QiF"34çìD«QiF

Outputs the input if it's not equal to the program. If it is equal, it will output the error:

** (RuntimeError) Could not convert "34çìD«QiF"34çìD«QiF to integer.

Try it online.

Explanation:

It's based on this base quine: "34çìD«"34çìD«.

"34çìD«QiF"           # Push string "34çìD«QiF"
           34ç        # Push 34, converted to a character: '"'
              ì       # Prepend it to the string: '"34çìDJQiF'
               D«     # Append a copy of itself: '"34çìDJQiF"34çìDJQiF'
                 Qi   # If it's equal to the (implicit) input-string:
                   F  #  Start a loop, using the (implicit) input-string as argument,
                      #  resulting in the error
                      # (implicit else: use the implicit input as implicit output)
\$\endgroup\$

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