Programming a Pristine World
Rail, 24 bytes
$'main' #
-[world]o/
I think this works. And it's both short and readable (as far as Rail goes).
- If the removed substring includes any part of
$'main'
we getInternal Error: Crash: No 'main' function found
. - If the removed substring includes the
#
, there is no way for the program to exit cleanly, so it will always terminate withCrash: No valid move
. I believe that it's not possible to delete a substring such that the track forms a valid (infinite) loop. - If the removed substring is in front of the
#
, it will be disconnected from the end of the track, so the train will crash (with the same error as above). - If the removed substring is after the
#
, it will also disconnect the#
from the end of the track (and potentially even the beginning of the track from the entry point$
). So again the same error.
As for the actual program: every Rail program needs to have a $'main'
(or a longer variant, but we're golfing here) as an entry point into the function and the train starts on the $
going South-East. Everything on that first line can be part of the track though, so removing the 'main'
the track is:
$ #
-[world]o/
The -
and /
are simply pieces of rail which we need to let the train take those 45° turns.
[world]
pushes the string world
and o
prints it. #
marks the end of the track - the only way to safely terminate a Rail program.
Interestingly, this solution is only possible because Rail allows the tracks to go through the main
line - if that wasn't possible #
would be after the first newline and the code could always be shortened to
$'main'
#
which is a valid program that doesn't do anything. (Non-space characters between '
and #
wouldn't affect that.)
Also quite interesting: if I had just golfed the task printing world
it wouldn't have been much shorter or simpler:
$'main'
-[world]o#
Funciton (186 136 bytes in UTF-16)
╔══════════════╗
║19342823075080╟
║88037380718711║
╚══════════════╝
This program prints “world”.
Most substrings you remove from this will stop it from being a complete box, which the parser will complain about. The only possible removals that leave a complete box are:
╔══════════════╗
|║19342823075080╟ (remove this whole line)
|║88037380718711║
╚══════════════╝
╔══════════════╗
║|19342823075080╟ ← substring starts at | here
║|88037380718711║ ← substring ends at | here
╚══════════════╝
... ↕ or anything in between these that removes a whole line’s worth ↕ ...
╔══════════════╗
║19342823075080|╟ ← substring starts at | here
║88037380718711|║ ← substring ends at | here
╚══════════════╝
╔══════════════╗
|║19342823075080╟
║88037380718711║ (both lines entirely)
|╚══════════════╝
╔══════════════╗
║19342823075080╟
|║88037380718711║ (remove this whole line)
|╚══════════════╝
Most of these remove the dangling end at the top right of the box, which is the output connector. Without this loose end, the box is just a comment:
╔══════════════╗
║88037380718711║
╚══════════════╝
This is no longer a valid program because the parser expects a program with exactly one output:
Error: Source files do not contain a program (program must have an output).
The only possibility that leaves an output connector is the last one of the above, which leaves this:
╔══════════════╗
║19342823075080╟
╚══════════════╝
However, this number does not encode a valid Unicode string in Funciton’s esoteric UTF-21. Try to run this, you get:
Unhandled Exception: System.ArgumentOutOfRangeException: A valid UTF32 value is between 0x000000 and 0x10ffff, inclusive, and should not include surrogate codepoint values (0x00d800 ~ 0x00dfff).
Therefore, this program is pristine.
Visual C++ - 96 95 bytes
#include<iostream>
#define I(a,b)a<<b
int main()I({std::cout,I('w',I('o',I('r',I('l','d';)))))}
Properties:
- You can't remove any part of
int main()
without a compile error. - You can't remove the modify the macros expansion AT ALL, removing
a
at all meansmain()
never gets{
, removingb
at all means our line doesn't end in a;
, removing<
meansstd::cout<'w'
causes an error, and removing<<
causesstd::cout'w'
,'w''o'
, etc. - You can't remove parameters from the macro definition or invocation, the only valid names for the definition would be
I(a)
,I(b)
which never match andI
which expands to before(
; on the other hand usingI(,
causes<<<<
, and,)
drops the semi-colon (barring any other errors). - You can't remove part of all of
std::cout
without running into a leading<<
, and therefore cannot remove any of#include<iostream>
in the beginning without a compile error. - You can't remove any part of a single character,
''
has an empty character error and'w,
, etc... try to making everything into one character. - You can't remove the left/right side of a macro without leaving too many
)
or(
on the other side, e.g. you cannot do things likeI('w',I('r'
.
Compiles online using Visual C++.
Once again this not an exhaustive proof. If you think you can get it too work without section be sure to let me know.
Previous versions used a considerably different approach and was proved to not be pristine so I've removed those scores.
Verification:
The following program has confirmed this version is pristine using the cl
compiler from Visual C++ 2010. Wished I had bothered to write this sooner:
#include <fstream>
#include <iostream>
char *S = "#include<iostream>\n#define I(a,b)a<<b\nint main()I({std::cout,I('w',I('o',I('r',I('l','d';)))))}";
//uncomment to print source code before compile
// #define prints
int main(){
for(int i=0; i<95; i++)
for(int j=i; j<95; j++){
std::fstream fs;
fs.open ("tmptst.cpp",std::fstream::out);
for(int k=0; k<95; k++)
if(k<i || k>j){
fs << S[k];
#ifdef prints
std::cout<<S[k];
#endif
}
fs.close();
#ifdef prints
std::cout<<'\n';
#endif
//Compile and surpress/pipe all output
//if it doesn't compile we get a nonzero errorlevel (i.e.true) from system.
if(!system("cl -nologo tmptst.cpp >x"))
return 0;
}
std::cout<<"PRISTINE!";
}