开发者

is it possible to write a program which prints its own source code utilizing a "sequence-generating-function"

开发者 https://www.devze.com 2022-12-30 08:01 出处:网络
is it possible to write a program which prints its own source code utilizing a \"sequence-generating-function\"?

is it possible to write a program which prints its own source code utilizing a "sequence-generating-function"?

what i call a sequence-generating-function is simply a function which returns a value out of a specific interval (i.e. printable ascii-charecters (32-126)). the point now is, that this generated sequence should be the programs own source-code. as you see, implementing a function which returns an arbitrary sequence is really trivial, but since the returned sequence must contain the implementation of the function itself it is a highly non-trivial task.

this is how such a program (and its corresponding output) could look like

开发者_如何学运维#include <stdio.h>

int fun(int x) {
    ins1;
    ins2;
    ins3;
    .
    .
    .
    return y;
}

int main(void) {
    int i;
    for ( i=0; i<size of the program; i++ ) {
        printf("%c", fun(i));
    }
    return 0;
}

i personally think it is not possible, but since i don't know very much about the underlying matter i posted my thoughts here. i'm really looking forward to hear some opinions!


If you know how to encode an array as a function (you seem to be saying you already know how to do this) then the Kleene Recursion theorem guarantees it can be done.

But for doubting Thomases, here's a C example. It has a program generating function that uses only +, -, *, / or calls other functions that use them.

Quines are always possible if you have Turing completeness and freedom to print what you like.


What you're referring to is a QUINE. Wiki's article on it is pretty good, with some helpful links. http://en.wikipedia.org/wiki/Quine_%28computing%29


To fly off at a tangent, try looking at Tupper's Self-Referential Formula.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号