![Very Happy :D](./images/smilies/ms-glad.png)
We are running out of puzzles..
Code: Select all
local z,o,r,g = require(("%s.%s"):format(select(2,...)))() -- edit2: added that last set of parens
print(loadstring((table.concat{z(g[1]) .. o(r[-1]) .. r(o[0]) .. g(z[ [[]] ])}):reverse())())
-- should return these five strings:
-- "Just", "another", "lua", "hackonaut", "."
-- Hints:
-- - Feel free to name the required file anything, it doesn't matter... much.
-- - Don't let the output misdirect your efforts.
Code: Select all
require "sm"
local a,b = sm(2)
local c = sm() -- same as sm(1)
local d,e = sm(2)
a("Four")
b(4)
c(a+1)
d(-0.0), e(1.0)
print(a + b, a - b, a * b, b / a, a % b, a ^ b)
-- "Eight" "Zero" "Sixteen" "One", "Null", "Two-hundred fifty-six"
print(a .. c, a*c+c*c)
-- "Forty-five" "Forty-five"
print(b .. c == b*c+c*c)
-- true
print(a/(e .. d)/c) -- edit3: fixed
-- "Zero dot zero eight"
print(a/c .. c/b) --edit3: added
-- 81.25
Code: Select all
function require ()
print("Just", "another", "lua", "hackonaut", ".")
os.exit()
end
Code: Select all
T(function (T) print 'fuzzy wuzzy'
T(function (T) print 'was a bear' end)
T(function (T) print 'had no hair' end)
end)
T(function (T) print 'was'
T(function (T) print 'not fuzzy' end)
end)
T(function (T) print 'he' end)
Define T.fuzzy wuzzy
was a bear
fuzzy wuzzy
had no hair
fuzzy wuzzy
was
not fuzzy
was
he
Code: Select all
local oldprint = print
T = setmetatable( {}, {
__call = function( _, func )
func( _ )
for i = 1, #T do
oldprint( T[i] )
end
table.remove( T, #T )
for i = #T, 2, -1 do
oldprint( T[i] )
end
end
} )
function print( str )
table.insert( T, str )
end
Now I am sorry I asked! He he. First time I encountered the "select" keyword, and "loadstring" too. Will stew in it a whilezorg wrote:here's one, good luck
Code: Select all
function T(f)
local msg
setfenv(f, setmetatable({print = function(s) msg=s print(s) end}, {__index = _G}))
f(function(f) T(f) print(msg) end)
end
Code: Select all
function double(x) return 2*x end
function rep(s) return s..s end
print((10 * double)(2))
print((3 * rep)"na", "BATMAN")
2048
nananananananana BATMAN
Code: Select all
debug.setmetatable(function() end,
{
__mul = function(amount, f)
return function(input)
for i = 1, amount do
input = f(input)
end
return input
end
end,
})
Users browsing this forum: Ahrefs [Bot] and 1 guest