85
8
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.
2Can a counter-example rely on input from STDIN? – Zacharý – 2017-07-20T14:17:46.420
6Would this make a good CnR? – CalculatorFeline – 2017-07-20T16:59:23.937
@CalculatorFeline: Only for languages where parsing is immediate (not performed in advance) - this is true of Bash and Batch for example. For those languages, I allow for a small exception - see the last Scoring point. – nneonneo – 2017-07-20T17:26:07.667
@Zacharý: I think that a counterexample is valid if any execution of the program can complete successfully (i.e. if there is some way to run the program such that it doesn't crash). Therefore, a string is not illegal if it can be embedded in some program that doesn't crash on some input. – nneonneo – 2017-07-20T17:27:27.053
@CalculatorFeline: As for CnR, I considered it during the sandbox proposal, but decided against it because legitimate solutions will receive zero robber submissions (i.e. things get boring for the robbers). But, if it turns out that a lot of submissions are faulty, I may convert the question to CnR so we can weed out non-illegal strings. – nneonneo – 2017-07-20T17:28:42.517
2Too late now I guess, but it seems like this could have been a cops and robbers challenge. There's a lot of skill evident in the attempts to make valid programs, as well as coming up with the strings in the first place. – user2390246 – 2017-07-21T07:43:31.900
Does it count if the standard IDE crashes at entering the string? (truely crashes) – Mega Man – 2017-07-23T08:16:43.203
5My condolences to the Perl attempts. :) – Kaz – 2017-07-23T15:40:46.197
@Kaz Well, there are only a finite number of Unicode characters that could be doubled to close an
s@
-like quote... – aschepler – 2017-07-24T11:32:51.727I think it is impossible in Perl 6 as you can use an arbitrary number of delimiting characters for a string literal
Q{{{{{{{{{{ab」}}」cd}}}}}}}}}}
(ab」}}」cd
), andQ
literals don't do any sort of interpretation of their contents. – Brad Gilbert b2gills – 2017-07-26T00:44:47.2871In forth this seems nearly impossible, given the ability to overwrite effectively any word/symbol. I'm sure there are probably ways to do it by redefining core system words but nothing that couldn't appear after some code that backs those words up as other words first. – reffu – 2018-02-14T17:18:48.167
@reffu Yeah, I tried to create one in Forth when the challenge was first posted. I didn't succeed. – mbomb007 – 2018-03-01T21:09:19.670
Can we assume that the program will not be given input? I have an answer, but only errors when no input is given, but works otherwise. – caird coinheringaahing – 2018-03-25T13:16:57.287
As long as you note that in your answer, I think it’s fair to assume no input. – nneonneo – 2018-03-25T17:56:39.677
2I'm pretty sure it's completely impossible in non-literate Haskell, thanks to nested comments. – dfeuer – 2019-03-19T01:50:46.317
1@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. – Ørjan Johansen – 2019-04-04T01:32:16.053This challenge rules out Turing Machine Language. – ouflak – 2019-09-12T13:50:43.877