Monday, March 22, 2010

Lua quine

For some reason lately I've seen an anomalous number of mention of quines, and figured it'd be time to try it out myself (I read about this question back in 1990s, but for some reason never got myself at solving it. here's the result in Lua.

function p(s)
print(s)
print("\ns = " .. string.format("%q", s) .. "\np(s)")
end

s = "function p(s)\n print(s)\n print(\"\\ns = \" .. string.format(\"%q\", s) .. \"\\np(s)\")\nend"
p(s)

And, just in case that blogger mucks up my quoting, here's a base64-encoded version:

ZnVuY3Rpb24gcChzKQogIHByaW50KHMpCiAgcHJpbnQoIlxucyA9ICIgLi4gc3RyaW5nLmZvcm1h
dCgiJXEiLCBzKSAuLiAiXG5wKHMpIikKZW5kCgpzID0gImZ1bmN0aW9uIHAocylcbiAgcHJpbnQo
cylcbiAgcHJpbnQoXCJcXG5zID0gXCIgLi4gc3RyaW5nLmZvcm1hdChcIiVxXCIsIHMpIC4uIFwi
XFxucChzKVwiKVxuZW5kIgpwKHMpCg==

No comments: