Tcl, 1073741823 (1G-1 bytes, cheating)
This is (obviously) cheating. It can be even larger in some languages like Bash, which doesn't load the whole program when it starts. Tcl runs very slow at starting, and finally refuses to run the program if the file size is about 2147483647 bytes or more.
set b binary
$b scan [$b format i [expr {[gets stdin]-1^3+[file size $argv0]*4}]] i a
puts $a
exit
#!!!!!#"!!!!#%!!!!#&!!!!#'!!!!#(!!!!#)!!!!#*!!!!#+!!!!#,!!!!#-!!!!#.!!!!#/!!!!#0!!!!#1!!!!#2!!!!#3!!!!#4!!!!#5!!!!#6!!!!#7!!!!#8!!!!#9!!!!#:!!!!#<!!!!#=!!!!#>!!!!#?!!!!#@!!!!#A!!!!#B!!!!#C!!!!#D!!!!#E!!!!#F!!!!#G!!!!#H!!!!#I!!!!#J!!!!#K!!!!#L!!!!#M!!!!#N!!!!#O!!!!#P!!!!#Q!!!!#R!!!!#S!!!!#T!!!!#U!!!!#V!!!!#W!!!!#X!!!!#Y!!!!#Z!!!!#[!!!!#^!!!!#_!!!!#`!!!!#a!!!!#b!!!!#c!!!!#d!!!!#e!!!!#f!!!!#g!!!!#h!!!!#i!!!!#j!!!!#k!!!!#l!!!!#m!!!!#n!!!!#o!!!!#p!!!!#q!!!!#r!!!!#s!!!!#t!!!!#u!!!!#v!!!!#w!!!!#x!!!!#y!!!!#z!!!!#{!!!!#|!!!!#~!!!!#!"!!!#""!!!#%"!!!#&"!!!#'"!!!#("!!!#)"!!!#*"!!!#+"!!!#,"!!!#-"!!!#."!!!#/"!!!#0"!!!#1"!!!#2"!!!#3"!!!#4"!!!#5"!!!#6"!!!#7"!!!#8"!!!#9"!!!#:"!!!#<"!!!#="!!!#>"!!!#?"!!!#@"!!!#A"!!!#B"!!!#C"!!!#D"!!!#E"!!!#F"!!!#G"!!!#H"!!!#I"!!!#J"!!!#K"!!!#L"!!!#M"!!!#N"!!!#O"!!!#P"!!!#Q"!!!#R"!!!#S"!!!#T"!!!#U"!!!#V"!!!#W"!!!#X"!!!#Y"!!!#Z"!!!#["!!!#^"!!!#_"!!!#`"!!!#a"!!!#b"!!!#c"!!!#
(...1073740323 more bytes...)
|%#m+Y|%#n+Y|%#o+Y|%#p+Y|%#q+Y|%#r+Y|%#s+Y|%#t+Y|%#u+Y|%#v+Y|%#w+Y|%#x+Y|%#y+Y|%#z+Y|%#{+Y|%#|+Y|%#~+Y|%#!,Y|%#",Y|%#%,Y|%#&,Y|%#',Y|%#(,Y|%#),Y|%#*,Y|%#+,Y|%#,,Y|%#-,Y|%#.,Y|%#/,Y|%#0,Y|%#1,Y|%#2,Y|%#3,Y|%#4,Y|%#5,Y|%#6,Y|%#7,Y|%#8,Y|%#9,Y|%#:,Y|%#<,Y|%#=,Y|%#>,Y|%#?,Y|%#@,Y|%#A,Y|%#B,Y|%#C,Y|%#D,Y|%#E,Y|%#F,Y|%#G,Y|%#H,Y|%#I,Y|%#J,Y|%#K,Y|%#L,Y|%#M,Y|%#N,Y|%#O,Y|%#P,Y|%#Q,Y|%#R,Y|%#S,Y|%#T,Y|%#U,Y|%#V,Y|%#W,Y|%#X,Y|%#Y,Y|%#Z,Y|%#[,Y|%#^,Y|%#_,Y|%#`,Y|%#a,Y|%#b,Y|%#c,Y|%#d,Y|%#e,Y|%#f,Y|%#g,Y|%
It computes the result with its own file size. So deleting anything will change the behavior.
The above program is generated by the C++ program below.
#include<fstream>
#include<string>
#include<cstring>
std::ofstream f("a.tcl");
const long long size = 0x3fffffffLL;
const std::string init = "set b binary\n"
"$b scan [$b format i [expr {[gets stdin]-1^3+[file size $argv0]*4}]] i a\n"
"puts $a\n"
"exit\n";
const std::string charset = "!\"%&'()*+,-./0123456789:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[^_`abcdefghijklmnopqrstuvwxyz{|~";
const int ncharset = 88;
int main() {
f<<init;
long long p = init.length();
int b[5] = {};
char ch[6] = "!!!!!";
while(p < size) {
f<<"#";
p++;
if(size-p > 5) {
f.write(ch, 5);
p += 5;
}
else {
f.write(ch, size-p);
break;
}
int i=0;
while(b[i] == ncharset-1) {
ch[i] = charset[b[i]=0];
i++;
}
ch[i] = charset[++b[i]];
}
f<<std::flush;
return 0;
}
The 7-zipped version of the complete program has only 18MB. Maybe I can upload it somewhere if someone request for it.
I chose Tcl because it has only a small number of special characters. So I could be sure one cannot implement the same functionality by selecting some characters not to delete. I guess Lisp is better on this.
1Do you mean negation as in
8 -> -8
or negation as in0100 -> 1011
? – Kyle Kanos – 2014-06-13T02:04:45.9001This SO Q&A suggests that, in general,
~x = -x - 1
, which is not the same thing as what you state. You need to clarify this, what exactly do you mean by negation. – Kyle Kanos – 2014-06-13T02:16:22.223I thought the bit complement was negation. Apparently not. – PyRulez – 2014-06-13T02:28:43.880
2About the "if any set of characters can be removed": does that only apply to consecutive characters or really any set of characters? – Martin Ender – 2014-06-13T07:06:52.137
To build on @m.buettner's question, how are long variable names counted? – Cephalopod – 2014-06-13T10:00:04.937
This is a completely objective criteria if you read the question. – PyRulez – 2014-06-13T15:38:19.277
Objective or not, I don't get it. Either way, it's not a good question. 1. If it refers to any arbitrary set of characters, every GolfScript answer containing a
~
, a)
and a~
after that will have a score of 3, no matter what those characters do (if anything) at the moment. 2. If it refers to consecutive characters, you can still use arbitrarily large strings, as long you check their lengths. – Dennis – 2014-06-14T04:58:49.727@Dennis There is an upper bound on length. Also, if your golf script works on many different formats, reducing it to
~(~
changes it's function, so wouldn't occur. – PyRulez – 2014-06-15T11:59:57.230@PyRulez: The upper bound is 1592 TB if we restrict ourselves to 1 byte characters. You got me convinced about removing the characters, but this will be extremely difficult to test. Even for a 256 byte program, there are over
10**77
different programs that can be formed just by removing characters. – Dennis – 2014-06-15T14:21:48.5101I retract my previous comment. This is actually a nice challenge; it's just very difficult to figure out whether a given solution is valid or not. All ideas I had to trivialize it were doomed to failure. – Dennis – 2014-06-16T04:58:14.913
I think as of Dennis's code this has gotten out of hand. There was a question recently where code had to be pointlessly contrived, but ever part had to have some semi-plausible software good practice justification. here it is
– Nathan Cooper – 2014-06-16T14:23:56.760@NathanCooper This question was sort of an experiment with restricted source and code bowling anyway. They were talking about nuking the tag on meta. – PyRulez – 2014-06-16T14:25:30.853