90
9
Let's define a pristine program as a program that does not have any errors itself but will error if you modify it by removing any contiguous substring of N characters, where 1 <= N < program length
.
For example, the three character Python 2 program
`8`
is a pristine program (thanks, Sp) because all the programs resulting from removing substrings of length 1 cause errors (syntax errors in fact, but any type of error will do):
8`
``
`8
and also all the programs resulting from removing substrings of length 2 cause errors:
`
`
If, for example, `8
had been a non-erroring program then `8`
would not be pristine because all the results of substring removal must error.
Your task in this challenge is to write the shortest pristine program possible that takes no input but outputs any one of the following five words:
world
earth
globe
planet
sphere
Which word you choose is entirely up to you. The sole word plus an optional trailing newline should be printed to stdout (or your language's closest alternative). The shortest program in bytes wins.
Notes:
- A standalone program is required, not a function.
- The words are case sensitive; outputting
World
orEARTH
is not allowed. - Compiler warnings do not count as errors.
- The erroring subprograms can take input or give output or do anything else as long as they always eventually error.
Here's a stack snippet that will list what programs need to error given a potentially pristine program:
<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'></script><script>function go() { var s = $('#i').val(), e = []; for (var i = 1; i < s.length; i++) { for (var j = 0; j <= s.length - i; j++) { e.push(s.substring(0, j) + s.substring(j + i)); } } $('#o').val(e.join('\n---\n')); }</script>Program:<br><textarea id='i' rows='16' cols='80'>`8`</textarea><br><button onclick='go()' type='button'>Go</button><br><br>Programs that should error: (--- separated)<br><textarea id='o' rows='16' cols='80'></textarea><br>
Does an exception being thrown in Java count as an error? What if I catch the exception? – geokavel – 2015-11-09T21:36:20.227
1@geokavel Yes. Catching the exception means it's no longer an error. – Calvin's Hobbies – 2015-11-09T21:37:40.157
34Twice as many deleted answers as non-deleted. That's an achievement! – DLosc – 2015-11-09T22:42:49.247
1Can a program read its own source code? – Shelvacu – 2015-11-11T17:57:56.173
@Shel Sure. (4more..) – Calvin's Hobbies – 2015-11-11T18:02:25.637
2Where to view the gravegard of "close but no cigar" answers and their comments? – Vi. – 2015-11-12T14:28:49.843
1
@Vi. Get 2,000 rep so you can view deleted posts.
– ThisSuitIsBlackNot – 2015-11-12T16:30:16.227What kind of errors are you talking about? just Compile and Runtime errors that make the program crash, or also logical errors that don't make the program crash but return a wrong output? – Nzall – 2015-11-12T23:52:21.127
@NateKerkhofs Errors that crash the program or prevent it from running. – Calvin's Hobbies – 2015-11-12T23:54:06.983
@Shel not sure if I am missing the context of your question because Calvin's PCG question makes my brain hurt but
<php echo file_get_contents(__FILE__); ?>
– MonkeyZeus – 2015-11-13T18:27:27.413@MonkeyZeus Sorry, I was asking if it was allowed, not if it was possible. – Shelvacu – 2015-11-13T19:07:54.090
Makes me wonder if Mathematica can have a pristine program that does anything useful. – LLlAMnYP – 2015-11-14T23:24:41.900
1This answer is now the shortest — should it be accepted instead? – Aidan F. Pierce – 2018-04-15T18:45:58.323
Is there a PristineScript language that has a built-in checksum in every program? – dan04 – 2019-04-09T23:47:33.887