So as you might or might not have known, a quine program is a program that outputs it's own source code. Since this is a lua scripting thread, I thought you guys might be interested in the lua quine code!
(deprecated)
[lua]
y = [[ print("y = [[" .. y .. "]]\ndostring(y)") ]]
dostring(y)
[/lua]
(working)
[lua]
s=[[io.write('s=[','[',s,']','];',s)]];io.write('s=[','[',s,']','];',s)
[/lua]
Tada! Try it out yourself at [url]http://www.lua.org/cgi-bin/demo[/url]
Or here's the hypothetical version of the quine code:
[lua]
s=print(s=print(s=print(s=print( --It goes on infinitely
[/lua]
[QUOTE=Toastermach10;27955709]So as you might or might not have known, a quine program is a program that outputs it's own source code. Since this is a lua scripting thread, I thought you guys might be interested in the lua quine code!
[lua]
y = [[ print("y = [[" .. y .. "]]\ndostring(y)") ]]
dostring(y)
[/lua]
Tada! Try it out yourself![/QUOTE]
To do this properly you'd do something like this.
print(file.Read(debug.getinfo(1).short_src))
Not what you posted.
[editline].[/editline]
Oh wait I see what you're doing. Took a couple of reads to understand what was happening.
Argh! It's deprecated from old lua syntax! Just tried it at [url]http://www.lua.org/cgi-bin/demo[/url], will upload a working one soon.
[quote]input:1: nesting of [[...]] is deprecated near '['[/quote]
[editline]9th February 2011[/editline]
Ninja'd.
Keep in mind this doesn't apply to Gmod lua specifically, just lua by itself. Try it out at the link above
[editline]9th February 2011[/editline]
Yes! Just tried out this and it works fine!
[lua]
s=[[io.write('s=[','[',s,']','];',s)]];io.write('s=[','[',s,']','];',s)
[/lua]
[editline]9th February 2011[/editline]
It looks odd, but It's just defining a variable whilst running the write function with the same variable concatenated within a string.
Neat. Pretty useless, but still neat.
[quote=http://en.wikipedia.org/wiki/Quine_(computing)]
For amusement, programmers sometimes attempt to develop the shortest possible quine in any given programming language.
[/quote]
:v:
I have a shorter one! :v:
[lua]input:1: '<name>' expected near '1'[/lua]
[editline]9th February 2011[/editline]
Ok, that was stupid, sorry for that. :saddowns:
Never tried to write quines, but those things look pretty fun to do when you're bored.
Nah, these guys have the shortest one, albeit in C: (International Obfuscated C Code Contest)
[quote]Worst abuse of the rules (...) An example is the world's shortest self-reproducing program. The entry was a program zero bytes in length that if run printed zero bytes to the screen (simply an empty file).[/quote]
:v:
Hahaha, now that's clever. :v:
Empty files are not quines, even if they technically print out their "source code", because there is no actual code in that case.
[editline]9th February 2011[/editline]
There's even a language that prints out "Empty files are not quines." when you try that :v:
:v:
Sorry, you need to Log In to post a reply to this thread.