95
13
This is a code golf challenge I thought of with a mathematical bent. The challenge is to write the shortest code possible such that it is an open question whether or not the code terminates. An example of what I mean could be the following piece of python code, adapted from an anwser to this cs stackexchange question.
def is_perfect(n):
return sum(i for i in range(1, n) if n % i == 0) == n
n = 3
while not is_perfect(n):
n = n + 2
Mathematicians conjecture that there are no odd perfect numbers, but it has never been proven, so no one knows if this piece of code will ever terminate. Can you come up with other pieces of code (perhaps relying on other open problems like the Collatz conjecture, or the twin primes conjecture) that are shorter, but for which it is unknown whether or not they terminate?
Edit: Some people have brought up a good additional rule - The solutions to the question should be deterministic. Although it might be even more interesting if you could find shorter solutions using nondeterminism. In this case, the rule would be to find a snippet for which the probability of termination is unknown.
2Welcome to PPCG! – Luis Mendo – 2016-10-22T00:03:08.787
3Your code can be golfed to 50 bytes:
n=3
while sum(k*(n%k<1)for k in range(1,n))-n:n+=2
. – xnor – 2016-10-22T01:24:43.24014This really is a great concept. It's nice to see original ideas like this. – Nathan Merrill – 2016-10-22T01:59:34.867
And here I thought this was going to be related to the Church-Turing thesis Nice question!
– MayorMonty – 2016-10-22T02:18:20.4401Useful – Post Rock Garf Hunter – 2016-10-22T05:23:09.407
May we assume infinite memory? – Mego – 2016-10-22T08:15:02.170
7@Mego I think this challenge only works if you assume infinite data types what will automatically assume infinite memory. – Martin Rosenau – 2016-10-22T09:41:46.917
54When I read the title I thought you wanted us to solve the halting problem AND golf the solution. – MrPaulch – 2016-10-22T12:00:35.617
1Are snippets explicitly allowed, or is it only full programs or functions? – Buffer Over Read – 2016-10-24T15:46:17.337
I love this challenge, because it's basically asking users to solve open-ended problems, which the world wants solved anyway. – mbomb007 – 2016-10-24T18:31:21.143
1
@WheatWizard I used this much longer list on Wikipedia.
– mbomb007 – 2016-10-24T18:32:49.503It is an open problem how long before cosmic rays trigger an infinite loop to NMI reset. – Joshua – 2016-10-24T19:55:48.340
This reminds me of the paper A Relatively Small Turing Machine Whose Behavior Is Independent of Set Theory, which details a Turing machine that runs forever but cannot be proven to do so using the axioms of ZFC set theory. (The paper even likens the construction of the Turing machine to "code-golfing.")
– 2012rcampion – 2016-10-25T03:13:35.407I think this should be closed: As soon as one of the used conjectures is proven, people have to delete their answers. And it is not too difficult to come up with own conjectures, that might have trivial answers. – flawr – 2016-10-25T09:30:03.377
We have already closed essentially this same question twice, IIRC. It has two major problems: 1. "Open question" under what assumptions? There are programs which are known to terminate if you assume some extremely strong axioms, but unknown otherwise. 2. It's a multi-duplicate of existing questions relating to Goldbach, Collatz, etc.
– Peter Taylor – 2016-10-26T14:38:32.410Is "Will you let this program run continuously for 10 years?" an open problem? – 12Me21 – 2018-12-30T17:48:46.287