Page 1 of 1
Self Displaying Program
Posted: Wed Jan 17, 2007 6:20 pm
by Konne
Code updated for 5.20+
This Program displays itsself in the debugger. Maybe someone can make it smaller.
Code: Select all
C.s="C.s=#:C=ReplaceString(C,Chr(35),Chr(34)+C+Chr(34)):Debug C":C=ReplaceString(C,Chr(35),Chr(34)+C+Chr(34)):Debug C
Posted: Wed Jan 17, 2007 7:06 pm
by Flype
waaahouuu that's so strange
what the use for such code ?
how it works ? i didn't understand at all your logic...
Posted: Wed Jan 17, 2007 7:20 pm
by Derek
That's clever.
Posted: Wed Jan 17, 2007 8:25 pm
by Henrik
lol

cool
Posted: Wed Jan 17, 2007 8:35 pm
by srod
Wow!
Posted: Wed Jan 17, 2007 11:02 pm
by Konne
Flype wrote:
what the use for such code ?
Normally you would think this would be a Infinity Recursive problem.
You may think it's impossible to make a Quote of a Quote etc
But thanks to Stringmanipulation it's possible
Once you understand the concept you have to make the program smaller. The one making the smallest PB Program wins

Posted: Wed Jan 17, 2007 11:07 pm
by srod
It nearly sent me crackers trying to figure out what the hell was going on!
It is very clever.
Posted: Thu Jan 18, 2007 2:57 am
by Tommeh
Ok, as we seem to be using PB hacks :p here is one for you
Code: Select all
String$ = "hello" ;String is defined
String$ = "world" ;String is redefined with new value
!MOV edx,dword _S1
!MOV [v_value],edx
Debug PeekS(value, 5) ;Get previous value
Debug PeekS(value+6, 5) ;Get new value
You can also use this method to retreve defined variable names and values :p
Posted: Thu Jan 18, 2007 1:54 pm
by Konne
It's not at all a PB Hack.
It's understandable with a couple of comments and the replacement of :'s.
Code: Select all
C.s="C.s=#:C=ReplaceString(C,Chr(35),Chr(34)+C+Chr(34)):Debug C" ;We save the Code in this Variable. # is then Replaced with " +Code +"
C=ReplaceString(C,Chr(35),Chr(34)+C+Chr(34)) ;Here we Replace # (Chr(35)) with the Code.And Two " (Chr(34))
Debug C ;Here we debug the Code
Posted: Wed Jan 24, 2007 7:37 am
by Rook Zimbabwe
C.s="C.s=#:C=ReplaceString(C,Chr(35),Chr(34)+C+Chr(34)):Debug C":C=ReplaceString(C,Chr(35),Chr(34)+C+Chr(34)):Debug C
OK keep in mind I am dense! but that is what pops up in debug... Oy I feel stupid for asking but that is what is
Supposed to happen???
Posted: Wed Jan 24, 2007 11:44 am
by Nik
It's a program that is capable of displaying it's own source code, thats called a quine see
http://en.wikipedia.org/wiki/Quine_%28computing%29
Posted: Wed Jan 24, 2007 2:21 pm
by JCV
1st kind of code to see in pb.
Re: Self Displaying Program
Posted: Mon Apr 18, 2016 2:45 pm
by #NULL
Konne wrote:This Program displays itsself in the debugger. Maybe someone can make it smaller.
i once posted one in the german forum:
http://forums.purebasic.com/german/view ... f=8&t=8471
apparently its 3 characters shorter

and there are still 4 spaces that can be eliminated..
Code: Select all
s$="s$=:Debug Mid(s$,1,3)+Chr(34)+s$+Chr(34)+Mid(s$,4,100)":Debug Mid(s$,1,3)+Chr(34)+s$+Chr(34)+Mid(s$,4,100)
Re: Self Displaying Program
Posted: Mon Apr 18, 2016 7:31 pm
by Demivec
#NULL wrote:Konne wrote:This Program displays itsself in the debugger. Maybe someone can make it smaller.
i once posted one in the german forum:
http://forums.purebasic.com/german/view ... f=8&t=8471
apparently its 3 characters shorter

and there are still 4 spaces that can be eliminated..
Code: Select all
s$="s$=:Debug Mid(s$,1,3)+Chr(34)+s$+Chr(34)+Mid(s$,4,100)":Debug Mid(s$,1,3)+Chr(34)+s$+Chr(34)+Mid(s$,4,100)
This code is shorter by 11 more characters (under 100)

.
Code: Select all
s.s="s.s=:Debug Mid(s,1,4)+Chr(34)+s+Chr(34)+Mid(s,5)":Debug Mid(s,1,4)+Chr(34)+s+Chr(34)+Mid(s,5)
Re: Self Displaying Program
Posted: Mon Apr 18, 2016 8:07 pm
by wilbert
Left will make it two chars shorter
Code: Select all
s.s="s.s=:Debug Left(s,4)+Chr(34)+s+Chr(34)+Mid(s,5)":Debug Left(s,4)+Chr(34)+s+Chr(34)+Mid(s,5)