+ 25

Is it possible to write a program whose output is the program itself?

4th Mar 2017, 7:55 PM
Baba Yunus Abdul Yekin
Baba Yunus Abdul Yekin - avatar
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)
7th Mar 2017, 10:25 AM
Anthony Vanover
Anthony Vanover - avatar
+ 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.
4th Mar 2017, 8:01 PM
Alper Tiryakioğlu
Alper Tiryakioğlu - avatar
+ 7
A code from Krishna Teja is just what you asked for ----- https://code.sololearn.com/cY6gVNvzeP9Z/?ref=app
15th Mar 2017, 5:50 AM
Utkαrsh
Utkαrsh - avatar
+ 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)
4th Mar 2017, 8:24 PM
MichaƂ Bujakowski
MichaƂ Bujakowski - avatar
+ 3
@Luka wrote a program here on sololearn as @Moksh said
11th Mar 2017, 5:51 AM
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer - avatar
+ 1
u can goole keyword "dynamic compile code"
6th Mar 2017, 6:12 PM
Cuong Nguyen Ngoc
Cuong Nguyen Ngoc - avatar
0
awesome
14th Mar 2017, 10:22 AM
Abbosjon Kudratov
Abbosjon Kudratov - avatar
- 1
yes..it is!! visit..gohacking.com
13th Mar 2017, 2:15 PM
vimal tomar
vimal tomar - avatar
- 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
11th Mar 2017, 4:17 AM
sniperisdemoman
sniperisdemoman - avatar
- 2
@Prasannakumar naik becouse they are lazy bustards. It's very wrong direction.
11th Mar 2017, 2:02 PM
MichaƂ Bujakowski
MichaƂ Bujakowski - avatar