+ 25
Is it possible to write a program whose output is the program itself?
11 Answers
+ 18
Yes, as a result of Kleene's recursion theorem they are possible in any Turing complete language. These programs are called Quines. Here's an example in Python:
s = 's = %r\nprint(s%%s)'
print(s%s)
+ 8
Yes, you can even output your program in another language. But I forgot what that was called though.
Really late EDIT: As Anthony Vanover said, these are quines.
+ 7
A code from Krishna Teja is just what you asked for -----
https://code.sololearn.com/cY6gVNvzeP9Z/?ref=app
+ 4
Yes, just look everywhere.
Internet browser runs pdf reader .
File browser runs exe file.
If You mean program which "borns" another program - yes, a class runs a class.
If You mean dynamic building by programs it's called Artificial Intelligence (AI) and google is almost there but they still use users and i hope it will not change for a very veeeeerrrryy looooong time.
Probably some simple applications complement some pre-built codes but if it will evoluate we will have a big problem called global AI, which can get out of controll in a very short time OR will be controlled by a very narrow group.
EDIT sorry, misunderstood but answered as well also. You have some tools to use OS console, to run it again.
Also You can encapsulate in Your code.
in IT everything's possible.
So written program is called "QUINE":
https://en.wikipedia.org/wiki/Quine_(computing)
+ 3
Microsoft has developed an AI it can write its own code.
https://www.linkedin.com/pulse/microsoft-has-created-ai-can-write-its-own-code-quharrison-terry?trk=v-feed&lipi=urn%3Ali%3Apage%3Ad_flagship3_feed%3BRm7suzGoF1cHHuMuYrog9A%3D%3D
+ 3
@Luka wrote a program here on sololearn as @Moksh said
+ 1
u can goole keyword "dynamic compile code"
0
awesome
- 1
yes..it is!!
visit..gohacking.com
- 2
In Java could it be possible to:
private int getLength = 0;
try {
File f = new File("Your_Program.java");
Scanner input = new Scanner(f);
While(input.hasNext()) {
getLength++;
}
input.close();
}
catch (IOException e) {
System.out.println("Could Not Read File");
e.printStackTrace();
}
try {
File f = new File("Your_Program.java");
Scanner input = new Scanner(f);
String[] x = new String[getLength];
While(input.hasNext()) {
x = input.next();
String y = x.split("\n");
System.out.println(y);
}
input.close();
}
catch (IOException e) {
System.out.println("Could Not Read File");
e.printStackTrace();
}
//Can't remember if you can only read non-rich text files with the File method or not, sorry if that's the case
- 2
@Prasannakumar naik
becouse they are lazy bustards.
It's very wrong direction.