105
\$\begingroup\$

The challenge is to find a string of characters that cannot appear in any legal program in your programming language of choice. That includes comments, strings, or other "non-executable" parts.

Challenge

  • Your program may be specific to a particular version or implementation of your language's compiler/interpreter/runtime environment. If so, please specify the particulars.
  • Only standard compiler/interpreter/runtime options are permitted. You cannot pass some weird flag to your compiler to get a specific result (e.g. passing a flag to convert warnings into errors).
  • If your programming language requires a specific encoding (e.g. UTF-8), your string must also be correctly encoded (i.e. strings which fail solely due to character decoding errors are not allowed).
  • Every individual character in your submission must be admissible in a legal program; that is, you can't just use a character which is always rejected.
  • The compiler/interpreter/runtime must give an error when given any source code that contains your string as a substring. The error does not have to be the same across programs - one embedding of your string might cause a syntax error, while another might cause a runtime error.

Scoring

  • Shortest illegal string for each language wins.
  • You should explain why your string is illegal (why it cannot appear anywhere in a legal program).
  • Dispute incorrect solutions in the comments. More specifically, you should provide a link to TIO or equivalent demonstrating a legal program (i.e. one that doesn't produce any errors) that contains the proposed substring.
  • Some languages (e.g. Bash, Batch, Perl) allow arbitrary binary data to be appended to a program without affecting validity (e.g. using __DATA__ in Perl). For such languages, you may submit a solution that can appear only in such a trailing section. Make sure to make a note of that in your answer. (The definition of this "trailing section" is language-dependent, but generally means any text after the parser has entirely stopped reading the script).

Example

In Python, I might submit

x
"""
'''

but this can be embedded into the larger program

"""
x
"""
'''
y
'''

so it isn't admissible.

\$\endgroup\$
17
  • 3
    \$\begingroup\$ Can a counter-example rely on input from STDIN? \$\endgroup\$
    – Adalynn
    Jul 20, 2017 at 14:17
  • 8
    \$\begingroup\$ Would this make a good CnR? \$\endgroup\$ Jul 20, 2017 at 16:59
  • 10
    \$\begingroup\$ My condolences to the Perl attempts. :) \$\endgroup\$
    – Kaz
    Jul 23, 2017 at 15:40
  • 6
    \$\begingroup\$ I'm pretty sure it's completely impossible in non-literate Haskell, thanks to nested comments. \$\endgroup\$
    – dfeuer
    Mar 19, 2019 at 1:50
  • 6
    \$\begingroup\$ @dfeuer That was my conclusion too. I even looked through GHC's lexer code to see if there was a loophole, but it seems very diligent about allowing absolutely every byte sequence inside sufficiently nested {- -} brackets. \$\endgroup\$ Apr 4, 2019 at 1:32

64 Answers 64

1 2
3
0
\$\begingroup\$

Milky Way, 2 bytes

Tries to execute an undefined opcode. Milky Way does not have comments. The newline is for ending strings.


)

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Turing Machine Code 5 bytes

Assuming block editing isn't allowed:

0

Or with the symbols showing:

< cr >< lf >
0
< cr >< lf >

Without block editing, it is impossible to stick this behind the comment symbol (';'), as the '0' will end up on the next line anyway. There is no block commenting in Turing Machine Code, a fact that is taken advantage of in other answers here as well. This patch of code would not only not run, it would kill the whole program before it can begin to execute, no matter where it is placed.

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Zig 0.6.0, 2 bytes


`

(\n`)

A newline will reset the tokenizer state, escaping any comments or multiline strings and erroring for single line strings. Backticks are not a valid character except in strings.

Try it online!

\$\endgroup\$
0
\$\begingroup\$

KonamiCode, 3 bytes

]()

Explanation:

First, the ] closes any comments this string might be placed in. Then, the () attempts to pass an empty number to the comment closing sign. Using the pynami interpreter, this will always result in an "This command doesn't have a parameter!" error, even if you put it inside a comment.

\$\endgroup\$
1 2
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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