Created
May 7, 2016 19:44
-
-
Save p440/5bac52031cd7705fb2518870a60c31fe to your computer and use it in GitHub Desktop.
icarus has found you
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do --welcome to the demo please paste me into lua.org/demo | |
local g = {s="\32",k="\37\99",n="\n"} --space, uhhh???, newline | |
local data = { | |
{0x49434152,0x55532046,0x4F554E44,0x20594F55,0x21212100}, --the message | |
{0x52554E20,0x5748494C,0x4520594F,0x55204341,0x4E212121}} --encoded in 4b segs | |
local f,r,w = string.format,string.rep,io.write --wrap some funcs for smallness | |
local dc = function (data) -- de coder | |
local d,f = {},math.floor --more smallness | |
d[1] = f(data/16777216) --first byte | |
d[2] = f((data-d[1]*16777216)/65536) --the second | |
d[3] = f((data-d[2]*65536)/256) --the third | |
d[4] = data-d[3]*256 --the end | |
return d[1],d[2],d[3],d[4] --spit em out | |
end | |
local p = 0 --ooh! create p (important) | |
p = function (data,i,j) --now define p | |
if (j or 0) >= (i or 0) then return end -- make sure we arent stupid | |
j = j or 0 -- again making sure | |
local w = function (data,i,j) -- prove i can use two funcs with the same name (very carefully) :^) | |
w(r(g.s,j)) --note: not a recursive call (yet). this is actually the upvalued "w": io.write; calling repeat string (spacing) | |
for _,e in ipairs(data[i]) do w(f(g.k:rep(4),dc(e))) end ---pull the data table apart, pass it through the decoder, write the message | |
w(g.n)--newline | |
end | |
w(data,1,j)--this actually calls the new "w" | |
j=j+1 | |
p(data,i,j) --now there is no upvalue "p" func just p=0... except at runtime this will be a pointer to the function... and thats how recursive calling works :^) | |
w(data,2,j-1)--write the rest | |
end | |
p(data,9)--i can do it, i will do it 9 times | |
end--my recursive call exercise | |
--[[OUTPUT: | |
ICARUS FOUND YOU!!! | |
ICARUS FOUND YOU!!! | |
ICARUS FOUND YOU!!! | |
ICARUS FOUND YOU!!! | |
ICARUS FOUND YOU!!! | |
ICARUS FOUND YOU!!! | |
ICARUS FOUND YOU!!! | |
ICARUS FOUND YOU!!! | |
ICARUS FOUND YOU!!! | |
RUN WHILE YOU CAN!!! | |
RUN WHILE YOU CAN!!! | |
RUN WHILE YOU CAN!!! | |
RUN WHILE YOU CAN!!! | |
RUN WHILE YOU CAN!!! | |
RUN WHILE YOU CAN!!! | |
RUN WHILE YOU CAN!!! | |
RUN WHILE YOU CAN!!! | |
RUN WHILE YOU CAN!!! | |
--]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment