30
2
A Fragile Quine
A fragile quine is a quine that satisfies the property of having each substring made by removing a single character, when evaluated, produces an error.
For example. If your program asdf
is a quine, then for it to be fragile, the following programs must error:
sdf
adf
asf
asd
Your program (and all of its substrings) must be fully deterministic, and must be in the same language. A program falling into an infinite loop (that is, failing to terminate), even if not eventually producing an error is considered to "produce an error" for the purposes of this challenge.
Standard loopholes apply, including the usual quine restrictions (e.g. not able to read own source code).
For example, print("foo")
is not fragile. All these substrings must error:
rint("foo")
pint("foo")
prnt("foo")
prit("foo")
prin("foo")
print"foo")
print(foo")
print("oo")
print("fo")
print("fo")
print("foo)
print("foo"
The ones that don't error are:
print("oo")
print("fo")
print("fo")
So it is not fragile.
An important note on quines
By consensus, any possible quine must satisfy this:
It must be possible to identify a section of the program which encodes a different part of the program. ("Different" meaning that the two parts appear in different positions.)
Furthermore, a quine must not access its own source, directly or indirectly.
Example
Since I consider JavaScript's function#toString to be "reading it's own source code", I am disallowing it. However, if I weren't to bar it, here is a fragile quine in JavaScript:
f=(n=b=`f=${f}`)=>(a=(n)==`f=${f}`,n=0,a)&(n!=b)?b:q
Tester
Here is a program that, given the source code of your program, generates all programs that must error.
let f = (s) =>
[...Array(s.length).keys()].map(i =>
s.slice(0, i) + s.slice(i + 1)).join("\n");
let update = () => {
output.innerHTML = "";
output.appendChild(document.createTextNode(f(input.value)));
};
input.addEventListener("change", update);
update();
#output {
white-space: pre;
}
#input, #output {
font-family: Consolas, monospace;
}
<input id="input" value="print('foo')">
<div id="output"></div>
Am I allowed HQ9+? – Oliver Ni – 2016-09-06T00:34:53.963
1
@OliverNi No
– Conor O'Brien – 2016-09-06T00:36:05.453Is infinite output considered a valid error? – PurkkaKoodari – 2016-09-06T06:44:08.903
Also, is it valid to print the correct output and then crash? – PurkkaKoodari – 2016-09-06T06:53:58.483
3
This is making assumptions about language features - not all languages have "errors".
– Mego – 2016-09-06T07:31:24.307+1 for disallowing
Function.prototype.toString
. – Neil – 2016-09-06T08:35:59.170@Mego Most languages have errors. I am not terribly worried about making this possible in all languages. – Conor O'Brien – 2016-09-06T11:07:51.257
@Pietu1998 infinite output implies infinite looping, so yes; if it crashes, then that constitutes an error. – Conor O'Brien – 2016-09-06T11:09:41.820
2@Mego Infinite loops are also allowed instead of errors. Every Turing-complete language has infinite loops. – feersum – 2016-09-06T12:19:35.673
@feersum Not true. Lambda calculus has recursion, not loops. It's not clear whether or not infinite recursion would count as an infinite loop. – Mego – 2016-09-06T17:35:22.473
@Mego how about running infinitely -.- – Conor O'Brien – 2016-09-06T19:38:27.670
@ConorO'Brien I have a million dollars for you if you can prove that an arbitrary program doesn't terminate. – Mego – 2016-09-06T19:48:29.580
1@Mego that is irrelevant. Why even bother bringing up the general case if only a finite subset applies per problem? – Conor O'Brien – 2016-09-06T20:07:55.617