Challenge: A Self-Replicating App

William Lancee

Well-Known Member
Licensed User
Longtime User
@Erel's Quizzes always generate a lot of interest. In this crisis of viral replication, I remembered a challenge from when I taught programming to Engineering students.

Without using the file system or the clipboard, write a minimal program that displays itself.

B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region
Sub Process_Globals
    Private fx As JFX
    Public MainForm As Form
End Sub
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    Dim textArea1 As TextArea: textArea1.Initialize("")
    MainForm.RootPane.AddNode(textArea1, 0, 0, MainForm.Width, MainForm.Height)
    MainForm.Title = "This is an exact replica of myself!"
    MainForm.Show
    'textArea1.Text =  ??              'In how many lines can you do this?   My best shot is 66 lines, including this preamble.
End Sub
 
I’m guessing that you should fill the textarea field in such a way that the content is a screen copy of the app.
 
i think you he wants to put the whole source code of a project in the textarea inside.
but it does not make any sense so maybe i am wrong :rolleyes:
 
write a minimal program that displays itself.


B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region
Sub Process_Globals
    Private fx As JFX
    Public MainForm As Form
End Sub
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    Dim textArea1 As TextArea: textArea1.Initialize("")
    MainForm.RootPane.AddNode(textArea1, 0, 0, MainForm.Width, MainForm.Height)
    MainForm.Title = "This is an exact replica of myself!"
    MainForm.Show
    textArea1.Text = "itself."
End Sub

;)
 
I'm not sure that I understand the challenge
I believe the topic is unfortunate and make it slightly confusing. I'd venture a guess that the challenge is to create an app that displays its own source.
 
Here you are..more or less.
It could be better and go to 100% accuracy, but it was just an exercise to prove itc ould be easily done.
Thanks for the challenge, it was a nice pastime for my afterlunch.
 

Attachments

Here you are..more or less.
It could be better and go to 100% accuracy, but it was just an exercise to prove itc ould be easily done.
Thanks for the challenge, it was a nice pastime for my afterlunch.
I'm pretty sure that it's not what @William Lancee means:
My best shot is 66 lines, including this preamble.

If, on the other hand, that is exactly what he meant... it is a big nonsense!
 
1. @udg is certainly almost right, but has some bugs. And some of those bugs not so easy to fix.
2. @LucaMs, it is much harder than it looks. @udg's method is not the only one. For example why don't you try it with smart strings.
3. I did not say my solution is the best. But it is funny to run the App from its copy and get another copy!
 
Back
Top